简体   繁体   English

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

[英]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: 我有以下我以前在另一个非常相似的项目上使用过的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

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: 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

Note that /wd/app is the expected output of pwd . 请注意, /wd/apppwd的预期输出。

OK, so clearly the issue must be with the last command, parcel build --public-url ./ prod/index.html . 好的,因此很明显问题出在最后一个命令, 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: 但是,当我直接在终端中运行此命令时,即使在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

So why does it fail when run from npm run prod ? 那么,为什么从npm run prod运行却失败了?

Not an extremely satisfying answer, but, I realize now that I accidentally ran npm install outside of the container. 这不是一个非常令人满意的答案,但是,我现在意识到我不小心在容器外部运行了npm install Still, the node_modules were installed in the same place, but clearly this made a difference in some other way. 尽管如此,将node_modules安装在同一位置,但是显然这在其他方面有所不同。 After rm -fr node_modules && npm install inside the container, things are working again. 在容器内rm -fr node_modules && npm install ,一切又rm -fr node_modules && npm install了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM