在Docker上安装npm got error不支持Node.js v13



我在 docker 中安装了 laravel 5.7 应用程序,当我进入 shell 并运行时

npm run watch-poll 

命令我收到错误:

npm does not support Node.js v13.0.0-pre

docker-compose.yml 有

version: '3.1'

web/Dockerfile.yml :

FROM php:7.2-apache
RUN apt-get update && 
apt-get install -y 
python 
libfreetype6-dev 
libwebp-dev 
libjpeg62-turbo-dev 
libpng-dev 
nano 
git-core 
curl 
build-essential 
openssl 
libssl-dev 
libgmp-dev 
libldap2-dev 
netcat 
sqlite3 
libsqlite3-dev 
&& git clone https://github.com/nodejs/node.git 
&& cd node 
&& ./configure 
&& make 
&& make install
RUN  docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/

RUN  docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif 
&& a2enmod rewrite
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

控制台中的完整输出:

$ docker-compose exec web bash
root@48dc23ea4799:/var/www/html# npm -v
6.11.3
root@48dc23ea4799:/var/www/html# node -v
v13.0.0-pre
root@48dc23ea4799:/var/www/html# uname -a
Linux 48dc23ea4799 4.15.0-65-generic #74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019 x86_64 GNU/Linux
root@48dc23ea4799:/var/www/html# npm run watch-poll
npm WARN npm npm does not support Node.js v13.0.0-pre
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
> @ watch-poll /var/www/html
> npm run watch -- --watch-poll
npm WARN npm npm does not support Node.js v13.0.0-pre
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
> @ watch /var/www/html
> npm run development -- --watch "--watch-poll"
npm WARN npm npm does not support Node.js v13.0.0-pre
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
> @ development /var/www/html                                                                                                                                                                                                                
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch" "--watch-poll"                                                            
sh: 1: cross-env: not found                                                                                                                                                                                                                  
npm ERR! code ELIFECYCLE                                                                                                                                                                                                                     
npm ERR! syscall spawn                                                                                                                                                                                                                       
npm ERR! file sh                                                                                                                                                                                                                             
npm ERR! errno ENOENT                                                                                                                                                                                                                        
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch" "--watch-poll"`                                    
npm ERR! spawn ENOENT                                                                                                                                                                                                                        
npm ERR!                                                                                                                                                                                                                                     
npm ERR! Failed at the @ development script.                                                                                                                                                                                                 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.                                                                                                                                           
npm WARN Local package.json exists, but node_modules missing, did you mean to install?                                                                                                                                                       
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-10-13T14_41_04_451Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch: `npm run development -- --watch "--watch-poll"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-10-13T14_41_04_473Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch-poll: `npm run watch -- --watch-poll`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ watch-poll script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-10-13T14_41_04_499Z-debug.log

如果有命令的方法

git clone https://github.com/nodejs/node.git

要安装 12 节点版本? 还是其他一些决定?

改 性:

我尝试安装交叉环境,但出现错误:

# npm install cross-env
npm WARN npm npm does not support Node.js v13.0.0-pre
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
> node-sass@4.9.3 install /var/www/html/node_modules/node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-79_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-79_binding.node": 
HTTP error 404 Not Found
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g. 
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
> uglifyjs-webpack-plugin@0.4.6 postinstall /var/www/html/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

> node-sass@4.9.3 postinstall /var/www/html/node_modules/node-sass
> node scripts/build.js
Building: /usr/local/bin/node /var/www/html/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 [
gyp verb cli   '/usr/local/bin/node',
gyp verb cli   '/var/www/html/node_modules/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 verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@13.0.0-pre | linux | 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` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.16
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 version: 13.0.0-pre
gyp verb command install [ '13.0.0-pre' ]
gyp verb install input version string "13.0.0-pre"
gyp verb detected "pre" node version 13.0.0-pre
gyp ERR! configure error 
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack     at install (/var/www/html/node_modules/node-gyp/lib/install.js:70:16)
gyp ERR! stack     at exports (/var/www/html/node_modules/node-gyp/lib/install.js:2:10)
gyp ERR! stack     at Object.self.commands.<computed> [as install] (/var/www/html/node_modules/node-gyp/lib/node-gyp.js:55:37)
gyp ERR! stack     at getNodeDir (/var/www/html/node_modules/node-gyp/lib/configure.js:79:20)
gyp ERR! stack     at PythonFinder.callback (/var/www/html/node_modules/node-gyp/lib/configure.js:44:7)
gyp ERR! stack     at PythonFinder.<anonymous> (/var/www/html/node_modules/node-gyp/lib/configure.js:471:14)
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:286:7)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at maybeClose (internal/child_process.js:1028:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:430:11)
gyp ERR! System Linux 4.15.0-65-generic
gyp ERR! command "/usr/local/bin/node" "/var/www/html/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/html/node_modules/node-sass
gyp ERR! node -v v13.0.0-pre
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm WARN You are using a pre-release version of node and things may not work as expected
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.9.3 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.9.3 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-10-14T03_42_11_550Z-debug.log

我有

HTTP error 404 Not Found

因为我在码头工人?

我必须再添加 1 个 RUN 命令:

**&& git clone https://github.com/nodejs/node.git 
&& cd node 
&& git checkout v12.0.0
&& ./configure 
&& make 
&& make install
RUN npm install cross-env
RUN  docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/**

npm 不支持 Node.js v13.0.0-pre 只是交战

真正的错误可能是这个

sh: 1: cross-env: not found  

如前所述@Daniel缺少交叉环境。

但是如果你想安装 node12,那么你需要在你的 Docekrfile 中添加这些。

RUN git clone https://github.com/nodejs/node.git && 
&& cd node 
&& git checkout v12.0.0
&& ./configure 
&& make 
&& make install
# better to intall packages it build time
RUN npm install --global cross-env watch-poll

最新更新