【问题标题】:How to run react project after installing dependencies from package.json从 package.json 安装依赖项后如何运行反应项目
【发布时间】:2019-09-04 22:59:47
【问题描述】:

我无法运行从 github 克隆的 react 项目。

克隆后,本地运行项目的步骤为:

  1. 从 package.json 安装依赖项:npm install && cd doc && npm install
  2. 要在本地服务器上运行文档页面:npm run docs:dev

我已经尝试将 package.json 中的行添加为 - "start": "webpack-dev-server --config=config/webpack.dev.js" 在 "scripts" 中显示错误。 文件package.json之前没有“start”,后来我加了。

这是我的 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 运行,但我收到了这个错误。

【问题讨论】:

  • 你得到的错误和堆栈跟踪是什么?
  • 你能发布 config/webpack.dev.js 吗?
  • 感谢您的回复...我已经编辑了上面的帖子,其中包含错误
  • 你发布了 webpack.config.js。您应该查找 webpack.dev.js,因为这是脚本中引用的内容
  • 对不起,错误地发布了 webpack.config.js... 我没有 webpack.dev.js 文件

标签: reactjs package.json


【解决方案1】:

上面也写得很清楚,你无权访问配置文件。看看有没有webpack.dev.js

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

【讨论】:

  • OK... 你能看看我在帖子中提到的从 package.json 安装依赖项的步骤吗?没看懂
【解决方案2】:

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

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

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

【讨论】:

  • 我在编辑“开始”后尝试过,但是,得到了同样的错误。你能看看我在帖子中提到的步骤吗?没看懂
  • @Pranav bhai,您是否将 --config 编辑为上述配置?
  • 是的,我编辑并复制了您发布的行,但出现了同样的错误...我想我犯了一些愚蠢的错误...您能在帖子中看到上面的步骤吗我已经提到了
  • 你能用 webpack.dev.js 的内容更新你的问题吗? codebrahma 的 react-lite-ui 开箱即用,虽然不在开发模式下。
  • 实际上我在“脚本”中添加了“开始”,当我克隆项目时它不可用。好吧,问题是如何从 package.json 安装依赖项,这在上面提到的步骤 1 中。它说... npm install && cd doc && npm install。我被困在这一步
猜你喜欢
  • 1970-01-01
  • 2016-08-02
  • 2016-09-09
  • 2022-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-25
相关资源
最近更新 更多