模块构建错误:pngquant ENOENT - webpack 构建在本地 OS X 上成功,在 AWS Ubuntu 16.04 服务器上失败
Posted
技术标签:
【中文标题】模块构建错误:pngquant ENOENT - webpack 构建在本地 OS X 上成功,在 AWS Ubuntu 16.04 服务器上失败【英文标题】:Module Build Error: pngquant ENOENT - webpack build succeeds on local OS X, fails on AWS Ubuntu 16.04 server 【发布时间】:2017-05-16 08:52:22 【问题描述】:我一直试图找到答案,但它似乎还没有出现。
我正在使用 React-Toolbox、React-Bootstrap 和一些自定义 scss。在我的本地机器上,构建工作正常。当我启动 AWS Ubuntu 服务器并进行基本节点生产设置时,我的图像构建失败。
我正在使用 Image-Webpack-Loader。我将它链接在文件加载器上。
这是我的生产 webpack 文件(对此的任何提示也非常感谢。永远学习)
let webpack = require('webpack');
let htmlWebpackPlugin = require('html-webpack-plugin');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const autoprefixer = require('autoprefixer');
const modulesPath = path.join(__dirname, 'node_modules');
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin(
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
);
var WebpackEnvPlugin = new webpack.DefinePlugin(
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
PORT: JSON.stringify(process.env.PORT)
);
module.exports =
entry: [
'./app/index.js'
],
output:
path: __dirname + '/dist',
filename: 'index_bundle.js',
publicPath: '/assets'
,
postcss: [autoprefixer],
resolve:
extensions: ['', '.css', '.scss', '.js', '.json'],
,
module:
loaders: [
test: /(\.js)$/,
exclude: /node_modules/,
loaders: ['babel']
,
test: /\.css$/,
exclude : path.join(__dirname, '/node_modules/react-toolbox/'),
loader: ExtractTextPlugin.extract("style-loader, css-loader!autoprefixer-loader") ,
test: /\.scss$/,
exclude : path.join(__dirname, '/node_modules/react-toolbox/'),
loader: ExtractTextPlugin.extract("style-loader", "css-loader!autoprefixer-loader!sass-loader")
,
test : /(\.scss|\.css)$/,
include : path.join(__dirname, '/node_modules/react-toolbox/'),
loaders : [
require.resolve('style-loader'),
require.resolve('css-loader') + '?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
require.resolve('sass-loader') + '?sourceMap'
]
,
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
]
,
plugins: [
HtmlWebpackPluginConfig,
WebpackEnvPlugin,
new ExtractTextPlugin('css/main.css',
allChunks: true
),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
]
我读到通过降低 pngquant 质量,问题可能会得到解决,但我没有这样的运气。
当我为不同的图像构建时,我遇到了这些错误:
ERROR in ./app/images/logo.png
Module build failed: Error: spawn /var/www/project/node_modules/pngquant-bin/vendor/pngquant ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./app/modules/listingpage/listingpage-component.js 55:11-43
我在index.js
中包含main.scss
文件的位置出错。
ERROR in ./app/stylesheets/scss/main.scss
Module build failed: ModuleBuildError: Module build failed: Error: spawn /var/www/project/node_modules/pngquant-bin/vendor/pngquant ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
at DependenciesBlock.onModuleBuildFailed (/var/www/project/node_modules/webpack-core/lib/NormalModuleMixin.js:315:19)
at nextLoader (/var/www/project/node_modules/webpack-core/lib/NormalModuleMixin.js:270:31)
at /var/www/project/node_modules/webpack-core/lib/NormalModuleMixin.js:292:15
at context.callback (/var/www/project/node_modules/webpack-core/lib/NormalModuleMixin.js:148:14)
at imagemin.buffer.then.catch.err (/var/www/project/node_modules/image-webpack-loader/index.js:42:9)
@ ./app/index.js 30:0-39
还有一个我认为与加载器有关的错误:
ERROR in ./app/images/magnifying-glass.png
Module build failed: Error: spawn /var/www/project/node_modules/pngquant-bin/vendor/pngquant ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./~/css-loader!./~/autoprefixer-loader!./~/sass-loader!./app/stylesheets/scss/main.scss 6:6846-6890
我使用以下格式包含我的图片:
const logo = require('../../images/logo.png');
最后,这是我的 package.json 依赖项:
"dependencies":
"async": "^2.0.1",
"autoprefixer": "^6.5.1",
"autoprefixer-loader": "^3.2.0",
"axios": "^0.14.0",
"babel-cli": "^6.16.0",
"babel-core": "^6.16.0",
"babel-loader": "^6.2.5",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.16.0",
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babel-register": "^6.16.3",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.15.2",
"bootstrap": "^3.3.7",
"classnames": "^2.2.5",
"compression": "^1.6.2",
"cookie-parser": "^1.4.3",
"css-loader": "^0.25.0",
"csv": "^1.1.0",
"dotenv": "^2.0.0",
"express": "^4.14.0",
"express-flash": "0.0.2",
"express-session": "^1.14.1",
"file-loader": "^0.9.0",
"glob": "^7.1.0",
"html-webpack-plugin": "^2.22.0",
"image-webpack-loader": "^2.0.0",
"immutability-helper": "^2.0.0",
"jquery": "^3.1.1",
"jwt-simple": "^0.5.0",
"later": "^1.2.0",
"lodash": "^4.16.3",
"moment": "^2.15.1",
"mongoose": "^4.6.1",
"morgan": "^1.7.0",
"multer": "^1.2.0",
"nodemon": "^1.11.0",
"postcss-loader": "^0.13.0",
"raw-loader": "^0.5.1",
"react": "^15.4.1",
"react-addons-css-transition-group": "^15.3.2",
"react-bootstrap": "^0.30.5",
"react-dom": "^15.3.2",
"react-redux": "^4.4.5",
"react-router": "^2.8.1",
"react-router-bootstrap": "^0.23.1",
"react-test-renderer": "^15.4.1",
"react-toolbox": "^1.2.3",
"redbox-react": "^1.3.1",
"redux": "^3.6.0",
"redux-logger": "^2.6.1",
"redux-thunk": "^2.1.0",
"request": "^2.75.0",
"rimraf": "^2.5.4",
"style-loader": "^0.13.1",
"webpack": "^1.13.2",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2"
,
"devDependencies":
"babel-eslint": "^7.0.0",
"babel-jest": "^15.0.0",
"babel-preset-es2015": "^6.16.0",
"chai": "^3.5.0",
"css-loader": "^0.25.0",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"image-webpack-loader": "^2.0.0",
"jest": "^15.1.1",
"jest-cli": "^15.1.1",
"json-loader": "^0.5.4",
"mocha": "^3.1.0",
"node-sass": "^3.10.1",
"raw-loader": "^0.5.1",
"react-addons-test-utils": "^15.3.2",
"redbox-react": "^1.3.1",
"redux-logger": "^2.6.1",
"sass-loader": "^4.0.2",
"toolbox-loader": "0.0.3",
"url-loader": "^0.5.7",
"webpack-dev-server": "^1.16.1"
我尝试过重新安装我的包,只是重新安装 Image-Webpack-Loader,所有基本的事情都要做。再一次,在本地构建良好,不在服务器上构建。我只是不确定我在这一点上做错了什么。在此先感谢您的帮助!
【问题讨论】:
嗨,你找到解决办法了吗?现在有点卡住了 据我回忆(该项目最终被废弃),我认为我最终所做的只是删除了图像加载器链中的 image-webpack-loader。我建议尝试一下。 【参考方案1】:正如 Rohn John 所说,我在我的机器上安装了 pngquant
和 optipng
并解决了问题
sudo apt-get install pngquant optipng
mkdir -p node_modules/pngquant-bin/vendor/
mkdir -p node_modules/optipng-bin/vendor/
ln -s /usr/bin/pngquant node_modules/pngquant-bin/vendor/pngquant
ln -s /usr/bin/optipng node_modules/optipng-bin/vendor/optipng
我测试了使用 yarn
可以做同样的事情并且更容易:
yarn add pngquant
yarn add optipng
yarn add cjpeg
【讨论】:
【参考方案2】:图像加载器依赖于pngquant
二进制文件。
当安装pngquant-bin
npm 模块时,它使用g++
、make
、bash
、zlib-dev
和libpng-dev
编译pngquant
二进制文件。
很遗憾,错误消息不够清晰,您只能看到一个无益的消息。
确保在npm install
或yarn install
之前运行以下命令。
apk --no-cache update \
&& apk --no-cache add make bash g++ zlib-dev libpng-dev \
&& rm -fr /var/cache/apk/*
您可以将安装g++ zlib-dev
替换为build-base
。
【讨论】:
很好的答案我必须将它添加到我的 alpine-node Dockerfile 中才能为我的应用程序正确加载 image-webpack-loader :)【参考方案3】:在对 node 和 npm 进行一些更新后出现了同样的问题。 尽管更新后一切正常,但由于显示您提到的消息而崩溃。 经过大量搜索后,我找不到另一个答案,所以我删除了 node_modules 文件夹并从头开始安装所有内容。 成功了……
【讨论】:
【参考方案4】:Alpine linux 的 pngquant 有问题,看看这个
https://github.com/imagemin/pngquant-bin/issues/65
对此的一种解决方案是通过在安装 npm/yarn 之前从源代码(如 https://git.alpinelinux.org/cgit/aports/tree/community/pngquant/APKBUILD )安装 pngquant 来链接它,但对于我来说,这对于一个软件包来说听起来太多了。
我也遇到了同样的问题,最终放弃了 alpine。我现在正在为节点使用标准 docker 映像。
【讨论】:
谢谢@avin45h!在没有意识到它可能是节点高山的情况下遇到了一些节点问题。【参考方案5】:在使用 rails capistrano 部署时遇到了这个问题,其中 node_modules 没有为 pngquant 正确创建。在那里找不到该命令。
最后用 capistrano 再次进行部署。
【讨论】:
【参考方案6】:好像在安装pngquant时遇到了一些问题。 错误信息 “模块构建失败:错误:spawn /var/www/project/node_modules/pngquant-bin/vendor/pngquant ENOENT” 表示在 node_modules/pngquant-bin/vendor/ 中找不到 pngquant。
您可以尝试重新安装 pngquant 或其他一些依赖于 pngquant 的 npm 包。
此外,您应该检查您的 Ubuntu 服务器是否安装了 pngquant。
【讨论】:
以上是关于模块构建错误:pngquant ENOENT - webpack 构建在本地 OS X 上成功,在 AWS Ubuntu 16.04 服务器上失败的主要内容,如果未能解决你的问题,请参考以下文章
模块构建失败:错误:spawn bin/rails ENOENT
Ionic app,错误:..main.ts模块构建失败:错误:ENOENT
为 pageserror 构建静态 HTML:错误:ENOENT:没有这样的文件或目录
Electron VueJS - 构建错误 - 无法注册应用程序协议。在 app.asar 中找不到 ENOENT、\dist_electron\bundled