[英]Unable to start project after create-react-app: Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js'
[英]react-scripts: not found on create-react-app project on ubuntu?
我正在使用這一
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
工作?
謝謝!
今天我遇到了同樣的問題,並再次運行安裝修復了該問題。
您需要做的就是再次將命令npm install
到項目中,這樣您就可以再次運行npm start
comand了!
為我工作! 希望我有所幫助!
當您將生成的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
進行./node_modules/react-scripts/bin/react-scripts.js
。 使用diff
將不會顯示差異,因為符號鏈接將得到解決。
最簡單的解決方案是在服務器上(即在Digitalocean上)創建一個臨時的react項目,然后使用copy -a
(而不是copy -r
,以保留符號鏈接) 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
跑:
sudo chown -R $USER:$USER '/home/ubuntu/.npm/'
在Linux OS上,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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.