从package.json安装依赖项后如何运行React项目

时间:2019-04-14 23:57:14

标签: reactjs package.json

我无法运行从github克隆的react项目。克隆之后,在本地运行项目的步骤是: 1.从package.json安装依赖项:npm install && cd doc && npm install 2.要在本地服务器上运行文档页面:npm运行docs:dev

我已经尝试过将package.json中的行添加为-“开始”:“脚本”中的“ webpack-dev-server --config = config / webpack.dev.js”,并显示了错误。 package.json文件之前没有“开始”文件,后来又添加了它

这是我的package.json文件,仅包含“脚本”部分

"scripts": {
    "start": "webpack-dev-server --config=config/webpack.dev.js",
    "docs:dev": "cd doc && npm run develop",
    "prebuild": "rm -rf dist components && npm run lint:fix",
    "build": "cross-env NODE_ENV=production webpack -p --config webpack.prod.js",
    "lint": "eslint ./ --ext .jsx --ext .js && echo \"eslint: no lint errors!\"",
    "lint:fix": "eslint ./ --ext .jsx --ext .js --fix && echo \"eslint: all errors fixed!\"",
    "test": "nyc mocha --require @babel/register --require jsdom-global/register --require test/testSetup.js --require test/ignoreStyles.js 'lib/**/*.test.js'",
    "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
    "semantic-release": "semantic-release"
  },

在“脚本”中添加该行时出现的错误 “开始”:“ webpack-dev-server --config = config / webpack.dev.js”为

module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\Pranav\Documents\GitHub\react-lite-ui\config
\webpack.dev.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at WEBPACK_OPTIONS (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modu
les\webpack-cli\bin\convert-argv.js:133:13)
    at requireConfig (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_module
s\webpack-cli\bin\convert-argv.js:135:6)
    at C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modules\webpack-cli\b
in\convert-argv.js:142:17
    at Array.forEach (<anonymous>)
    at module.exports (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modul
es\webpack-cli\bin\convert-argv.js:140:15)
    at Object.<anonymous> (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_m
odules\webpack-dev-server\bin\webpack-dev-server.js:92:55)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-lite-ui@1.0.2 start: `webpack-dev-server --config=config/webpack.
dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-lite-ui@1.0.2 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Pranav\AppData\Roaming\npm-cache\_logs\2019-04-15T07_57_27
_526Z-debug.log

这是webpack.config.js文件

const merge = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
   devtool: 'inline-source-map',
   mode: 'development',
});

我希望该项目应该以npm run start运行,但是会出现错误

2 个答案:

答案 0 :(得分:0)

还清楚地表明您无权访问配置文件。查看是否有webpack.dev.js

  

错误:找不到模块   'C:\ Users \ Pranav \ Documents \ GitHub \ react-lite-ui \ config   \ webpack.dev.js'

答案 1 :(得分:0)

您的npm启动不正确,请使用以下内容。

 "start": "webpack-dev-server --config ./config/webpack.dev.js",

-config = config / webpack.dev.js不正确。