【问题标题】:react-scripts: not found on create-react-app project on ubuntu?react-scripts:在 ubuntu 上的 create-react-app 项目中找不到?
【发布时间】:2016-12-26 07:16:19
【问题描述】:

我正在使用这个来开发 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 工作?

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 在我的情况下失败了,因为我在 CI 平台上使用了npm ci。因此,在本地运行 npm install 并将 package-lock.json 提交到 git 之后 - 一切顺利。
    • 但是为什么不使用npm ci 进行安装!?我想在我的 CI 环境中使用 ci 命令
    【解决方案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 不会显示差异,因为符号链接将被解析。

    最简单的解决方案是在服务器上(即在 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
    

    【讨论】:

      【解决方案3】:

      运行:

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

      sudo chown -R $USER:$USER

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

      【讨论】:

        猜你喜欢
        • 2019-04-26
        • 2021-04-02
        • 2019-11-19
        • 1970-01-01
        • 2019-12-30
        • 1970-01-01
        • 2018-01-25
        • 2020-07-21
        • 2018-04-25
        相关资源
        最近更新 更多