当从npm shell脚本运行时,为什么宗地命令失败,而直接运行时,宗地命令为何失败?

时间:2019-06-29 20:40:43

标签: npm parceljs

我以前在另一个非常相似的项目中使用过以下prod脚本:

#!/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

echo $(pwd)是最近的尝试,目的是确认我是否健全,但是不幸的是,当我使用npm run prod运行该目录时,它会打印出预期的目录,并且出现错误,看起来不是很正常有用的:

/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

请注意,/wd/apppwd的预期输出。

好,所以很明显问题出在最后一个命令parcel build --public-url ./ prod/index.html上。

但是当我直接在终端中运行此命令时,即使在npm run prod错误发生之后,我实际上也获得了成功:

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

那么为什么从npm run prod运行时失败了?

1 个答案:

答案 0 :(得分:0)

这不是一个非常令人满意的答案,但是,我现在意识到我不小心将npm install移出了容器。 node_modules仍然安装在同一位置,但是显然这在其他方面有所不同。在容器中rm -fr node_modules && npm install之后,事情又恢复了。

相关问题