javascript - React 模块安装失败

标签 javascript reactjs npm yarnpkg

我正在尝试通过 yarnnpm 安装 sass-loadernode-sass ,但得到同样的错误。

我尝试使用其中之一:

yarn add sass-loader@6.0.6 node-sass@4.5.3
npm install sass-loader@6.0.6 node-sass@4.5.3

但两者都会产生类似的错误。这是 yarn 的回应:

编辑:我正在使用 Windows。设置 python 路径后,这是我得到的响应:

[3/4] Linking dependencies...
warning " > react-modal@2.2.2" has incorrect peer dependency "react@^0.14.0 || ^
15.0.0".
warning " > react-modal@2.2.2" has incorrect peer dependency "react-dom@^0.14.0
|| ^15.0.0".
[4/4] Building fresh packages...
[-/2] ? waiting...
error C:\Users\sagil\Desktop\ReactTutorial\indecision-app\node_modules\node-sass
: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: C:\Users\sagil\Desktop\ReactTutorial\indecision-app\node_modules\node
-sass
Output:
Building: C:\Program Files\nodejs\node.exe C:\Users\sagil\Desktop\ReactTutorial\
indecision-app\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass
_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'C:\\Users\\sagil\\Desktop\\ReactTutorial\\indecision-app\\node_m
odules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.7.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\sagil\Desktop\ReactTut
orial\indecision-app\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\sagil\Desktop\ReactTutorial\indecisio
n-app\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\sagil\Desktop\ReactTutorial\indecisio
n-app\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:158:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:\Users\sagil\Desktop\ReactTut
orial\indecision-app\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Users\sagil\Desktop\ReactTutorial\indecisio
n-app\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Users\sagil\Desktop\ReactTutorial\indecisio
n-app\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at C:\Users\sagil\Desktop\ReactTutorial\indecision-a
pp\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:158:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (
C:\\Users\\sagil\\Desktop\\ReactTutorial\\indecision-app\\node_modules\\which\\w
hich.js:13:12)\n    at F (C:\\Users\\sagil\\Desktop\\ReactTutorial\\indecision-a
pp\\node_modules\\which\\which.js:68:19)\n    at E (C:\\Users\\sagil\\Desktop\\R
eactTutorial\\indecision-app\\node_modules\\which\\which.js:80:29)\n    at C:\\U
sers\\sagil\\Desktop\\ReactTutorial\\indecision-app\\node_modules\\which\\which.
js:89:16\n    at C:\\Users\\sagil\\Desktop\\ReactTutorial\\indecision-app\\node_
modules\\isexe\\index.js:42:5\n    at C:\\Users\\sagil\\Desktop\\ReactTutorial\\
indecision-app\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplet
e (fs.js:158:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\Python27\python.EXE
gyp verb check python version `C:\Python27\python.EXE -c "import sys; print "2.7
.13
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node v
ersion: 10.7.0
gyp verb command install [ '10.7.0' ]
gyp verb install input version string "10.7.0"
gyp verb install installing version: 10.7.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 10.7.0
gyp verb ensuring nodedir is created C:\Users\sagil\.node-gyp\10.7.0
gyp verb created nodedir C:\Users\sagil\.node-gyp\10.7.0
gyp http GET https://nodejs.org/download/release/v10.7.0/node-v10.7.0-headers.ta
r.gz
gyp WARN install got an error, rolling back install
gyp verb command remove [ '10.7.0' ]
gyp verb remove using node-gyp dir: C:\Users\sagil\.node-gyp
gyp verb remove removing target version: 10.7.0
gyp verb remove removing development files for version: 10.7.0
gyp ERR! configure error
gyp ERR! stack Error: connect ETIMEDOUT 104.20.22.46:443
gyp ERR! stack     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1163:1
4)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\sagil\\Deskto
p\\ReactTutorial\\indecision-app\\node_modules\\node-gyp\\bin\\node-gyp.js" "reb
uild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--l
ibsass_library="
gyp ERR! cwd C:\Users\sagil\Desktop\ReactTutorial\indecision-app\node_modules\no
de-sass
gyp ERR! node -v v10.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this comm

我已尝试按照其中一个错误中的说明下载 python 2.7。但错误仍然存​​在。我坚持了 3 个小时,希望得到一些帮助。

会不会是一些权限问题?我不明白为什么会这样,因为我只是一步一步地遵循基本教程。

最佳答案

node-gyp 在 Windows 上构建失败是很常见的情况。 要使构建通过,请按照 official documentation 中描述的步骤操作

完成此工作的最简单方法是安装 windows-build-tools使用 npmyarn

npm install --global --production windows-build-tools

然后再次尝试安装 node-sasssass-loader

这个问题也可以通过使用Bash on Ubuntu on windows来解决。

关于javascript - React 模块安装失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51822990/

相关文章:

javascript - 什么是必要的逃生舱口?

javascript - 根据某些字母显示字符串

javascript - Reactjs 使用套接字 : rerender when socket receive a message

node.js - 永远的日志不断增长

node.js - 如何获取在forever npm 中运行的NodeJs 应用程序的日志?

node.js - npm - 有关已安装 Node 模块命令行参数的问题

javascript - 如何使用 jquery 突出显示与数字匹配的所有列

javascript - create-react-app 显示错误 "You need to enable JavaScript to run this app."

javascript - React - 使用 cssModules 和 url-loader 配置 Next.js

javascript - GraphQl 中的注册身份验证不起作用 : Error:- signupUser: null