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"
  }
}

这是我的node版本npm

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

我该如何解决这个问题并制作npm run build作品?

谢谢!

4

3 回答 3

2

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

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

为我工作!我希望我有帮助!

于 2017-04-16T18:05:12.583 回答
2

当您将生成的 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
$ 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
于 2017-01-03T17:18:49.103 回答
0

跑:

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

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

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

sudo chown -R $USER:$USER

来源:create-react-app 失败,权限被拒绝

于 2019-02-07T18:26:59.620 回答