react-scripts:在ubuntu上的create-react-app项目中找不到?

时间:2016-12-26 07:16:19

标签: node.js ubuntu npm create-react-app react-scripts

我正在使用这个

开发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 个答案:

答案 0 :(得分:2)

我今天遇到了同样的问题,我修复了它再次运行安装。

您需要做的就是再次将npm install命令发送到您的项目中,这样您就可以再次运行npm start命令了!

适合我! 我希望我能得到帮助!

答案 1 :(得分:1)

将生成的create-react-app项目复制到另一个目录(即将其部署到服务器时)时,由于未保留符号链接,因此失败。见https://github.com/facebookincubator/create-react-app/issues/200react-scripts中的文件./node_modules/.bin/需要与./node_modules/react-scripts/bin/react-scripts.js进行符号链接。使用diff不会显示差异,因为符号链接将被解析。

最简单的解决方案是在服务器上创建临时反应项目(即在Digitalocean上),然后使用copy -a(而不是copy -r复制./node_modules/.bin的内容。为了保留符号链接)。

$ create-react-app tempReact
$ copy -a tempReact/node_module/.bin/* myActualReactApp/node_module/.bin

另一种解决方案是手动重新创建符号链接。

$ ln -s myActualreactApp/node_module/react-scripts/bin/react-scripts.js myActualReactApp/node_module/.bin/react-scripts

答案 2 :(得分:0)

  

运行:

     

sudo chown -R $USER:$USER '/home/ubuntu/.npm/'

     

在Linux操作系统上,NPM和NodeJS与sudo一起全局安装,并且该文件的所有者是root,通常用户只能读取/执行该软件包。当NPM停止时,由根创建一个〜/ .npm /文件夹。通过运行create-react-app,您以用户身份执行命令,而create-react-app尝试修改〜/ .npm /目录中的某些内容,该目录由根用户拥有,而不是当前用户拥有。您需要将目录的所有者更改为您,以便您可以在没有sudo特权的情况下对其进行修改。

     

当您使用sudo安装NPM软件包时,通常会发生类似的事情。 sudo npm install --save。同样,新安装的软件包归根所有,例如,当您尝试更新/修改/删除您的项目而没有sudo侵害NPM时,您将遇到类似的权限错误。在这些情况下,请浏览至您的项目目录并通过运行以下命令更改其所有者:

     

sudo chown -R $USER:$USER

来源:create-react-app fails with permission denied