我正在尝试<model-viewer>
使用 Rails 6 和 Webpacker,但它抛出了一些错误:
model-viewer-legacy.js:272 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
at model-viewer-legacy.js:272
at Module.<anonymous> (model-viewer-legacy.js:432)
at Module../node_modules/@google/model-viewer/dist/model-viewer-legacy.js (model-viewer-legacy.js:56169)
at __webpack_require__ (bootstrap:19)
at Object../app/javascript/packs/application.js (application.js:23)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
model-viewer.min.js:32923 Uncaught TypeError: Cannot read property 'prototype' of undefined
at HTMLElement.value (model-viewer.min.js:32923)
at HTMLElement.value (model-viewer.min.js:32159)
at HTMLElement.value (model-viewer.min.js:31802)
at HTMLElement.value (model-viewer.min.js:31539)
at vp.preRender (model-viewer.min.js:26317)
at vp.render (model-viewer.min.js:26337)
at model-viewer.min.js:26229
at model-viewer.min.js:11427
at r (model-viewer.min.js:6941)
我已经使用它添加了它,yarn add @google/model-viewer
并且我正在application.js
像这样加载它:
require("@google/model-viewer/dist/model-viewer.min");
require("@google/model-viewer/dist/model-viewer-legacy");
这是的内容webpack/environment.js
:
const { environment } = require('@rails/webpacker')
const customConfig = require('./custom');
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
})
)
environment.config.merge(customConfig);
module.exports = environment
这是内容webpack/custom.js
:
module.exports = {
resolve: {
alias: {
jquery: 'jquery/src/jquery'
}
}
};
任何人都知道如何让这个工作?我习惯了 Rails 4 管道,发现整个 webpacker 的东西超级混乱。