How to run my own forked parse-server

Hi guys,

I have forked parse server to work on a PR and would like to test my fork in production.

I am following notes here: parse-server/CONTRIBUTING.md at master · parse-community/parse-server · GitHub, namely the instructions to point my app to my forked branch.

  1. I change my package.json and point parse-server towards my fork via "parse-server": "git+https://github.com/mman/parse-server.git#master"
  2. I delete node_modules to make sure working directory is clean
  3. I run npm install as instructed, and then npm start and everything works.

That is on the Mac, with node 14.

When I do the same inside pristine node based Docker container using:

  1. docker run -it -v $(pwd):/src node:14 bash
  2. npm install
  3. npm start fails with:

Error: Cannot find module '/var/app/current/node_modules/parse-server/lib/index.js'. Please verify that the package.json has a valid "main" entry

The same error is described here: amazon elastic beanstalk - How to deploy a commit of parse server? - Stack Overflow.

Examining node_modules/parse-server reveals that `src/ directory is gone, and lib/ directory was not produced.

This must be some babel magic that I am not familiar with. The stackoverflow answer points towards committing lib/ into git but that is clearly not a proper solution after reading the contribution guide

Could you please help me get forward? What is the correct procedure please?

thanks,
Martin

There is something strange happening. I can now reliably reproduce the fail in docker and I absolutely do not know why, here is the simplest example.

  1. docker run -it node:14 bash
  2. mkdir /wrk && cd /wrk
  3. git clone https://github.com/parse-community/parse-server-example.git
  4. Change package.json to make parse-server point towards git+https://github.com/parse-community/parse-server.git#master
  5. npm install

No error is produced, everything seems to be fine.

npm start then fails with the following error:

root@643f86cca930:/wrk/parse-server-example# npm start 

> [email protected] start /wrk/parse-server-example
> node index.js

internal/modules/cjs/loader.js:311
      throw err;
      ^

Error: Cannot find module '/wrk/parse-server-example/node_modules/parse-server/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/wrk/parse-server-example/index.js:5:21)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/wrk/parse-server-example/node_modules/parse-server/package.json',
  requestPath: 'parse-server'

According to the npm documentation, installing a dependency from git should install its dev dependencies and invoke prepare phase, which in turn invokes npm run build for parse-server dependency. Which in turns invokes babel src/ -d lib/ --copy-files.

Interestingly enough, src is not present, and lib is not produced.

This is what fails inside Docker but somehow works fine under Mac.

Anybody familiar with babel and the src/ lib/ dance here?
Martin

The problem that you see happens because the lib is in Parse Server .gitignore file: parse-server/.gitignore at master · parse-community/parse-server · GitHub

So this folder is present in the npm package but not in the GitHub repo, meaning that you can install parse-server from npm but it does not work if you just install directly from GitHub.

In order to overcome this problem I use to remove the lib folder from the .gitignore file in my fork

Hi David,

so the problem is not .gitignore file actually. It’s a bit more tricky. Let me please elaborate my understanding.

  1. Parse Server only publishes to github.com its src/ folder.
  2. src/ folder needs to be compiled with babel to produce lib/. This is described by the build step in Parse Servers’ package.json.
  3. The build step is invoked automatically by npm’s prepare script that is run automatically at certain points of npm package’s lifecycle.
  4. For example prepare step is invoked by npm when publishing the official package to npm registry. Thus for official releases, npm registry will only contain lib/ directory of parse-server and not its src/.
  5. The prepare step it is also called automatically when npm installing parse-server dependency via git, which is what is needed when you depend on forked parse-server version. For example like this:
npm install --save git+https://github.com/mman/parse-server#master

On a dev machine this works great, but it fails under docker.

The reason why it fails is nicely described here: Docker: Installing npm packages from github - burnedikt.

In short, npm install when run as root (a fairly usual Dockerfile setup) will fallback to unprivileged user when running all scripts, and will emit an innocent invisible warning (sic!) message that prepare script was not called at all, thus rendering the parse-server unusable.

Initially you think everything is fine:

npm verb prepareGitDep git+https://github.com/mman/parse-server.git#master: installing devDeps and running prepare script.

But then it fails:

npm sill prepareGitDep npm WARN lifecycle [email protected]~prepare: cannot run in wd [email protected] npm run build (wd=/root/.npm/_cacache/tmp/git-clone-f02a80e5)

The solution suggested by the poster to use npm install --unsafe-perm did not work for me under docker either, and the only proper solution was to use non-privileged dedicated user to build the image. For official node docker images there is a node user with /home/node home directory that can be used to build the custom package.

Here is my Dockerfile for reference:

FROM       node:14
MAINTAINER Martin Man <[email protected]>

EXPOSE 1337

USER root
RUN apt-get update && apt-get dist-upgrade -y
RUN apt-get update && apt-get install -y curl jq awscli

USER node
WORKDIR /home/node

RUN mkdir MyParseServer
WORKDIR MyParseServer

COPY package.json package.json
COPY package-lock.json package-lock.json

RUN npm install

COPY cloud cloud
COPY templates templates
COPY index.js index.js
COPY healthcheck.sh healthcheck.sh

CMD [ "npm", "start" ]

HEALTHCHECK CMD /home/node/MyParseServer/healthcheck.sh

I will be filing a PR to improve the contribution guide and clarify this step, as it seems that every now and then somebody gets bitten by it and the only solution I found within the fist 20 hours was to not .gitignore the lib/ folder and push it to github.com, which is not nice and clean and complicates the creation of pull requests further down the line.

1 Like

Nice investigation @enodev!