我的使用了Rails和Webpack的应用在Docker容器中运行良好,6.0.3.4版本也没有问题。
"webpack": "^4.44.1",
"webpack-cli": "^3.3.9"
在升级到6.1.0版本后,webpack-cli 在执行assets:precompile
期间无法读取environment.js中的 'plugins'(或者 'config' 或者 'loaders')属性。
...Step 20/22 : RUN bundle exec rake RAILS_ENV=staging assets:precompile
---> Running in bca898bb9014
yarn install v1.22.5
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > tempusdominus-bootstrap-4@5.39.0" has unmet peer dependency "moment@^2.29.0".
warning " > tempusdominus-bootstrap-4@5.39.0" has unmet peer dependency "moment-timezone@^0.5.31".
warning " > tempusdominus-bootstrap-4@5.39.0" has unmet peer dependency "tempusdominus-core@5.19.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has incorrect peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
Done in 4.28s.
I, [2021-01-10T14:31:28.268903 #7] INFO -- : Writing /var/www/<RoR-app>/public/assets/manifest-a72913f4c604bc8f97dd576fc8777bf029401f6af0e14b6a6c9d3874acfe73e4.js
I, [2021-01-10T14:31:28.269857 #7] INFO -- : Writing /var/www/<RoR-app>/public/assets/manifest-a72913f4c604bc8f97dd576fc8777bf029401f6af0e14b6a6c9d3874acfe73e4.js.gz
Compiling...
Compilation failed:
warning package.json: No license field
[webpack-cli] Failed to load '/var/www/<RoR-app>/config/webpack/production.js'
[webpack-cli] TypeError: Cannot read property 'plugins' of undefined
at Object.<anonymous> (/var/www/<RoR-app>/config/webpack/environment.js:7:13)
at Module._compile (/var/www/<RoR-app>/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (/var/www/<RoR-app>/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/var/www/<RoR-app>/config/webpack/production.js:3:21)
at Module._compile (/var/www/<RoR-app>/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
ERROR: Service 'ruby' failed to build: The command '/bin/sh -c bundle exec rake RAILS_ENV=staging assets:precompile' returned a non-zero code: 1
config/webpack/production.js
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
config/webpack/environment.js
const { environment } = require('@rails/webpacker');
const webpack = require('webpack');
const expose = require('./loaders/expose');
const coffee = require('./loaders/coffee');
const erb = require('./loaders/erb');
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
Popper: ['popper.js', 'default'],
Rails: ['@rails/ujs'],
moment: 'moment'
})
);
...
package.json
{
"dependencies": {
"@rails/ujs": "^6.1.1",
"@rails/webpacker": "^6.0.0-pre.1",
"bloodhound-js": "^1.2.3",
"bootstrap": "^4.5.3",
"clean-webpack-plugin": "^3.0.0",
"cocoon": "github:nathanvda/cocoon#c24ba53",
"core-js": "^3.8.2",
"css-loader": "^5.0.1",
"exports-loader": "^1.1.1",
"expose-loader": "^1.0.3",
"file-loader": "^6.2.0",
"font-awesome": "^4.7.0",
"jbuilder": "^0.0.5",
"jquery": "^3.5.1",
"jquery-ui": "^1.12.1",
"jquery-ui-dist": "^1.12.1",
"jquery-ujs": "^1.2.2",
"jstree": "^3.3.11",
"popper.js": "^1.16.1",
"sidekiq": "^1.1.1",
"tempusdominus-bootstrap-4": "^5.39.0",
"turbolinks": "^5.2.0",
"webpack": "^5.12.2",
"webpack-cli": "^4.3.1",
"webpack-dev-middleware": "^4.0.2",
"webpack-dev-server": "^3.11.1"
},
"devDependencies": {}
}