bbarker
bbarker

Reputation: 13088

Why might a parcel command fail when run from an npm shell script, but not when run directly?

I have the following prod script I've used previously on another, very similar project:

#!/usr/bin/env sh

GCC=$(npm bin)/google-closure-compiler

preGccBuildSteps () {
  rimraf prod dist && mkdir prod && ln -sfn ../../css prod/css && \
    spago build && spago bundle-module --main Metajelo.UI --to prod/index.prod.js && \
    cp static/index.* prod/
}


preGccBuildSteps || { echo 'preGccBuildSteps failed' ; exit 1; }
"$GCC" --js prod/index.prod.js --js_output_file prod/index.opt.js && \
  echo $(pwd) && \
  parcel build --public-url ./ prod/index.html

The echo $(pwd) is a recent addition to try to confirm I'm sane, but unfortunately, it prints out the expected directory when I run it using npm run prod and I get an error that seems not very helpful:

/wd/app
[Error: ENOENT: no such file or directory, scandir 'build'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'build'
}
/wd/node_modules/parcel-luxe/lib/parser.js:44
    files.forEach(function (file) {
          ^

TypeError: Cannot read property 'forEach' of undefined
    at /wd/node_modules/parcel-luxe/lib/parser.js:44:11
    at /wd/node_modules/parcel-luxe/lib/reader.js:9:14
    at FSReqCallback.oncomplete (fs.js:136:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! purescript-metajelo-ui@ prod: `../scripts/prod`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the purescript-metajelo-ui@ prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/brandon/.npm/_logs/2019-06-29T20_34_37_583Z-debug.log

Note that /wd/app is the expected output of pwd.

OK, so clearly the issue must be with the last command, parcel build --public-url ./ prod/index.html.

But when I run this in the terminal directly, even just after the error with npm run prod, I actually get success:

brandon@4747aec8d9e1:/wd/app$ parcel build --public-url ./ prod/index.html
✨  Built in 6.10s.

dist/prod.0a64bfcf.js.map     547.15 KB    107ms
dist/prod.0a64bfcf.js          253.9 KB    5.56s
dist/index.html                 5.01 KB    375ms
dist/prod.74dcbc56.css.map      4.46 KB      5ms
dist/icomoon.0cf994d0.svg       3.53 KB     40ms
dist/icomoon.6cd840b1.eot       1.95 KB     40ms
dist/icomoon.a7482a13.woff      1.86 KB     39ms
dist/prod.74dcbc56.css          1.82 KB    5.50s
dist/icomoon.712d3017.ttf       1.79 KB     39ms

So why does it fail when run from npm run prod?

Upvotes: 0

Views: 675

Answers (1)

bbarker
bbarker

Reputation: 13088

Not an extremely satisfying answer, but, I realize now that I accidentally ran npm install outside of the container. Still, the node_modules were installed in the same place, but clearly this made a difference in some other way. After rm -fr node_modules && npm install inside the container, things are working again.

Upvotes: 1

Related Questions