针对多个HTML文件时,Usemin创建ELIFECYCLE错误

时间:2019-01-07 01:25:47

标签: node.js json npm node-modules

我目前正在完成Coursera上的“前端Web UI框架和工具:Bootstrap 4”课程,并且遇到了NPM脚本问题。在package.json文件中创建脚本以最小化文件并将它们传输到分发文件夹时,在尝试对根文件夹中的三个单独的html文件运行usemin脚本时,我一直收到ELIFECYCLE错误。对于我的一生,我无法弄清楚为什么我会不断收到此错误,因为它的编写与课堂上讲授的完全相同。我还尝试过对这些文件分别使用usemin,其中一个文件有效,而其他两个则不起作用。由于我对编程没有足够的经验,因此我将不胜感激,并且正在尝试通过此类在线课程来学习更多知识,并且已经在这个问题上停留了一个多星期,这将极大地感谢您的帮助。我也无法通过Google搜索找到有关此问题的任何有用信息。

{
  "name": "confusion",
  "version": "1.0.0",
  "description": "This is a website for Ristorante Con Fusion",


  "main": "index.html",
  "scripts": {
    "start": "npm run watch:all",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lite": "lite-server",
    "scss": "node-sass -o css/ css/",
    "watch:scss": "onchange \"css/*.scss\" -- npm run scss",
    "watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\"",
    "clean": "rimraf dist",
    "copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/",
    "imagemin": "imagemin img/* -o dist/img",
    "usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
    "build": "npm run clean && npm run copyfonts && npm run imagemin && npm run usemin"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "copyfiles": "^2.1.0",
    "cssmin": "^0.4.3",
    "htmlmin": "0.0.7",
    "imagemin": "^6.1.0",
    "lite-server": "^2.3.0",
    "node-sass": "^4.11.0",
    "onchange": "^3.3.0",
    "parallelshell": "^3.0.1",
    "rimraf": "^2.6.2",
    "uglifyjs": "^2.4.11",
    "usemin": "^0.5.0",
    "usemin-cli": "^0.5.1"
  },
  "dependencies": {
    "bootstrap": "^4.0.0",
    "bootstrap-social": "^5.1.1",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "popper.js": "^1.12.9"
  }
}

这是我收到的错误日志:

    0 info it worked if it ends with ok
    1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
    1 verbose cli   'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli   'run',
    1 verbose cli   'usemin' ]
    2 info using npm@6.5.0
    3 info using node@v10.13.0
    4 verbose run-script [ 'preusemin', 'usemin', 'postusemin' ]
    5 info lifecycle confusion@1.0.0~preusemin: confusion@1.0.0
    6 info lifecycle confusion@1.0.0~usemin: confusion@1.0.0
    7 verbose lifecycle confusion@1.0.0~usemin: unsafe-perm in lifecycle true
    8 verbose lifecycle confusion@1.0.0~usemin: PATH: C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\User\Desktop\Programming Courses\CoursEra\Front-End Web UI Frameworks and Tools\Bootstrap4\conFusion\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Sublime Text 3;C:\Users\User\AppData\Roaming\npm
    9 verbose lifecycle confusion@1.0.0~usemin: CWD: C:\Users\User\Desktop\Programming Courses\CoursEra\Front-End Web UI Frameworks and Tools\Bootstrap4\conFusion
    10 silly lifecycle confusion@1.0.0~usemin: Args: [ '/d /s /c',
    10 silly lifecycle   'usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html' ]
    11 silly lifecycle confusion@1.0.0~usemin: Returned: code: 1  signal: null
    12 info lifecycle confusion@1.0.0~usemin: Failed to exec usemin script
    13 verbose stack Error: confusion@1.0.0 usemin: `usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html`
    13 verbose stack Exit status 1
    13 verbose stack     at EventEmitter.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
    13 verbose stack     at EventEmitter.emit (events.js:182:13)
    13 verbose stack     at ChildProcess.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
    13 verbose stack     at ChildProcess.emit (events.js:182:13)
    13 verbose stack     at maybeClose (internal/child_process.js:962:16)
    13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
    14 verbose pkgid confusion@1.0.0
    15 verbose cwd C:\Users\User\Desktop\Programming Courses\CoursEra\Front-End Web UI Frameworks and Tools\Bootstrap4\conFusion
    16 verbose Windows_NT 6.1.7601
    17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "usemin"
    18 verbose node v10.13.0
    19 verbose npm  v6.5.0
    20 error code ELIFECYCLE
    21 error errno 1
    22 error confusion@1.0.0 usemin: `usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html`
    22 error Exit status 1
    23 error Failed at the confusion@1.0.0 usemin script.
    23 error This is probably not a problem with npm. There is likely additional logging output above.
    24 verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:0)

我在做同样的课程,并且遇到类似的错误。但是,我只是能够解决它。我通过重新安装所有开发依赖项并使用当前版本(而不是本课程中的版本)来完成此操作。我也确实将usemin命令(根据我在这里找到的另一个来源)更改为

“ imagemin”:“ imagemin img / * --out-dir = dist / img”,

但是,它仍然无法正常工作,因此我使用以下工具检查了所有文件中的错误:

https://www.freeformatter.com/java-regex-tester.html用于测试html文件; http://www.webtoolkitonline.com/javascript-tester.html用于测试.js文件,而https://jsonlint.com/?json=用于测试package.json文件是否存在错误。

我纠正了所有文件后,命令“ npm run build”终于起作用了。