在Ubuntu上创建的create-react-app项目中找不到react-scripts?

3
我正在使用reactjs,并使用此链接:https://github.com/facebookincubator/create-react-app
但是,当我在Ubuntu 16上使用DigitalOcean进行部署时,我无法运行npm run build,并且出现以下错误。
deploy@xxxx:/www/tmdb_admin$ sudo npm run build
[sudo] password for deploy: 

> tmdb_admin@0.1.0 build /www/tmdb_admin
> react-scripts build

sh: 1: react-scripts: not found

npm ERR! Linux 4.4.0-57-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
npm ERR! node v7.3.0
npm ERR! npm  v4.0.5
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! tmdb_admin@0.1.0 build: `react-scripts build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the tmdb_admin@0.1.0 build script 'react-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the tmdb_admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs tmdb_admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls tmdb_admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /www/tmdb_admin/npm-debug.log

这是我的package.json文件。

{
  "name": "tmdb_admin",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "autoprefixer-stylus": "0.10.0",
    "concurrently": "3.0.0",
    "react-scripts": "0.6.1",
    "stylus": "0.54.5"
  },
  "dependencies": {
    "bulma": "^0.2.3",
    "case-sensitive-paths-webpack-plugin": "^1.1.4",
    "es6-promise": "^4.0.5",
    "font-awesome": "^4.7.0",
    "isomorphic-fetch": "^2.2.1",
    "jwt-simple": "^0.5.0",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "react-pagify": "^2.1.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.4.0",
    "react-router-redux": "^4.0.4",
    "react-slick": "^0.14.5",
    "redux": "^3.5.2",
    "redux-thunk": "^2.1.0",
    "segmentize": "^0.4.1",
    "slick-carousel": "^1.6.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "watch": "concurrently --names 'webpack, stylus' --prefix name 'npm run start' 'npm run styles:watch'",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "styles": "stylus -u autoprefixer-stylus ./src/css/style.styl -o ./src/css/style.css",
    "styles:watch": "stylus -u autoprefixer-stylus -w ./src/css/style.styl -o ./src/css/style.css"
  }
}

这是我的nodenpm版本。

deploy@xxxx:~$ node -v
v7.3.0
deploy@xxxx:~$ npm -v
4.0.5

我该如何修复这个问题并让npm run build正常工作呢?

谢谢!

3个回答

2

今天我遇到了同样的问题,后来通过重新安装解决了。

你只需要在项目中再次运行命令npm install,这样你就可以再次运行npm start命令!

对我来说有效!希望我的回答能帮到你!


在我的情况下失败了,因为我在CI平台上使用了npm ci。所以在本地运行npm install并将package-lock.json提交到git后 - 一切都顺利进行。 - Shevchenko Viktor
但是为什么使用 npm ci 安装不起作用呢?我想在我的 CI 环境中使用 ci 命令。 - Anthony Manning-Franklin

2
当您将一个生成的create-react-app项目复制到另一个目录(即在部署到服务器时),它会失败,因为符号链接未被保留。请参见 https://github.com/facebookincubator/create-react-app/issues/200。在./node_modules/.bin/中的react-scripts文件需要被链接到./node_modules/react-scripts/bin/react-scripts.js。使用diff将不显示差异,因为符号链接将被解析。
最简单的解决方案是在服务器上创建一个临时的React项目(例如在Digitalocean上),然后使用copy -a(而不是copy -r)复制./node_modules/.bin目录的内容,以便保留符号链接。
$ create-react-app tempReact
$ cp -a tempReact/node_modules/.bin/* myActualReactApp/node_modules/.bin

另一种解决方法是手动重新创建符号链接。
$ ln -s myActualreactApp/node_modules/react-scripts/bin/react-scripts.js myActualReactApp/node_modules/.bin/react-scripts

0
运行: ``` sudo chown -R $USER:$USER '/home/ubuntu/.npm/' ``` 在Linux操作系统中,NPM和NodeJS是通过sudo全局安装的,文件的所有者是root,通常用户只能读取/执行那些包。当安装NPM时,会由root创建一个~/.npm/文件夹。通过运行create-react-app,您正在以用户身份执行命令,并且create-react-app正在尝试修改位于~/.npm/目录中的某些内容,该目录由root拥有而不是当前用户。您需要更改该目录的所有者,以便您可以在没有sudo特权的情况下进行修改。
通常,在使用sudo安装NPM包时也会发生类似的情况,例如sudo npm install --save。同样,新安装的包由root拥有,例如当您尝试在NPM前面不加sudo的情况下更新/修改/删除项目时,您将遇到类似的权限错误。在这些情况下,转到您的项目目录并通过运行以下命令更改其所有者: ``` sudo chown -R $USER:$USER ```
来源:create-react-app fails with permission denied

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接