我在使用webpacker的Rails应用程序。
我有一个开始如下的条目文件:
MJML
我将grapesjs-mjml
的纱线以及Cannot find module "."
的纱线安装到了应用程序的nodes_modules文件夹中。
我不断遇到未捕获的错误:import mjml2html from 'mjml'
是由grapesjs-mjml模块内部的{
"name": "my-app",
"private": true,
"dependencies": {
"mjml": "^4.4.1"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@rails/webpacker": "3.5",
"babel-loader": "^8.0.6",
"caniuse-lite": "1.0.30000697",
"coffeescript": "1.12.7",
"grapesjs": "^0.14.52",
"grapesjs-mjml": "^0.1.10",
"grapesjs-navbar": "^0.1.5",
"grapesjs-preset-webpage": "^0.1.10",
"prop-types": "^15.6.0",
"webpack": "^3.4.1",
"webpack-dev-server": "2.11.2",
"webpack-merge": "^4.1.1"
}
}
引起的。
我竭尽所能。包括一堆babel插件。
我正在使用所有grapesjs-mjml开发依赖项。这是我的package.json:
const environment = require('./environment')
const merge = require('webpack-merge');
module.exports = merge({
module: {
rules: [
{
test: /\.m?js$/,
enforce: 'pre',
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-syntax-dynamic-import"],
["@babel/plugin-proposal-object-rest-spread"],
["@babel/plugin-proposal-class-properties"]
]
}
},
]
},
externals: {
'grapesjs': 'grapesjs',
'jquery': 'jQuery'
},
}, environment.toWebpackConfig());
我的Rails开发Webpack配置如下:
WARNING in ./node_modules/mjml-core/lib/helpers/mjmlconfig.js
89:9-80 Critical dependency: the request of a dependency is an expression
at RequireResolveContextDependency.getWarnings (me/node_modules/webpack/lib/dependencies/ContextDependency.js:39:18)
at Compilation.reportDependencyErrorsAndWarnings (me/node_modules/webpack/lib/Compilation.js:702:24)
at Compilation.finish (me/node_modules/webpack/lib/Compilation.js:565:9)
at applyPluginsParallel.err (me/node_modules/webpack/lib/Compiler.js:502:17)
at me/node_modules/tapable/lib/Tapable.js:289:11
at _addModuleChain (me/node_modules/webpack/lib/Compilation.js:511:11)
at processModuleDependencies.err (me/node_modules/webpack/lib/Compilation.js:481:14)
at process._tickCallback (internal/process/next_tick.js:61:11)
@ ./node_modules/mjml-core/lib/helpers/mjmlconfig.js
@ ./node_modules/mjml-core/lib/index.js
@ ./node_modules/mjml/lib/index.js
@ ./node_modules/grapesjs-mjml/src/command-export-mjml.js
@ ./node_modules/grapesjs-mjml/src/commands.js
@ ./app/javascript/packs/grapesJSMJML.js
@ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/grapesJSMJML.js
webpack: Compiled with warnings.
我收到webpac服务器报告的警告,但我认为这与之无关:
Reference
任何人都知道我应该做什么?
答案 0 :(得分:0)
尝试像这样导入“ grapesjs-mjml / src / blocks”。
import loadBlocks from 'grapesjs-mjml/src/blocks';
import loadComponents from 'grapesjs-mjml/src/components';
import loadCommands from 'grapesjs-mjml/src/commands';
import loadButtons from 'grapesjs-mjml/src/buttons';
import loadStyle from 'grapesjs-mjml/src/style';
答案 1 :(得分:0)
在我的情况下(每个案例都不同),此问题已解决,方法是在webpack配置中的解析中添加模拟。