有没有办法解决'npm ERR! “ react.js中的代码ELIFECYCLE”

时间:2019-05-22 10:44:56

标签: npm-scripts

我正在尝试使用Django框架作为后端并使用React.js作为前端来创建应用程序。 django部分工作正常,但是当尝试将react与我的应用程序集成时。我收到 npm错误!代码ELIFECYCLE npm ERR! errno 2 。我对这项技术还很陌生,因此我并不会默默地了解错误的来源。

我尝试清理缓存并删除node_modules存储库,然后进行npm install,但是它不起作用。所以我求助于您,向熟练的程序员寻求帮助

这是我得到的错误:

ERROR in Entry module not found: Error: Can't resolve './gentelella/frontend/src/index.js' in 'C:\Users\USER\Desktop\finale\django-gentelella\gentelella'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! gentelella@1.0.0 build: `webpack --mode production ./gentelella/frontend/src/index.js --output ./gentelella/frontend/static/frontend/main.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the gentelella@1.0.0 build 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!     C:\Users\USER\AppData\Roaming\npm-cache\_logs\2019-05-22T10_24_53_635Z-debug.log

这是package.json:

{
  "name": "gentelella",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  },
  "devDependencies": {
    "@babel/core": "^7.4.4",
    "@babel/preset-env": "^7.4.4",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "webpack": "^4.32.0",
    "webpack-cli": "^3.3.2"
  },
  "scripts": {
    "dev": "webpack --mode development ./gentelella/frontend/src/index.js --output ./gentelella/frontend/static/frontend/main.js",
    "build": "webpack --mode production ./gentelella/frontend/src/index.js --output ./gentelella/frontend/static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

1 个答案:

答案 0 :(得分:0)

在我看来,您的道路是错误的。尝试使用从路径中删除gantelella文件夹的方法,这样就留下了'frontend / src / index.js'。

这假设您已经按照以下方式构造了文件夹: C:\ Users \ USER \ Desktop \ finale \ django-gentelella \ gentelella \ frontend \ src \ index.js