我刚刚将我的离子应用升级到最新版本,该应用程序正确编译,但是在执行时,我会收到以下错误:
Uncaught Error: Cannot find module "module"
at webpackMissingModule (index.js:3)
at Object.<anonymous> (index.js:3)
at Object.module.exports.Aacute (index.js:34)
at __webpack_require__ (bootstrap 4ed551a6084ccd9f1ad5:54)
at Object.<anonymous> (loadRc.js:5)
at __webpack_require__ (bootstrap 4ed551a6084ccd9f1ad5:54)
at Object.<anonymous> (createExplorer.js:6)
at Object.<anonymous> (createExplorer.js:159)
at __webpack_require__ (bootstrap 4ed551a6084ccd9f1ad5:54)
at Object.exports.endianness (index.js:5)
我将错误追溯到node_modules/require-from-string/index.js
上的这一行:
'use strict';
var Module = require('module'); // <--This line
var path = require('path');
在我看来,某些东西在离子上没有正确配置,但我似乎找不到缺少的配置。由于这些模块是节点的一部分,所以我不知道会发生什么。
离子信息ionic info
是:
cli packages: (/Users/MyUser/.nvm/versions/node/v7.10.0/lib/node_modules)
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : ios 4.5.4
Ionic Framework : ionic-angular 3.9.2
System:
ios-deploy : 1.9.2
ios-sim : 6.1.2
Node : v7.10.0
npm : 4.2.0
OS : macOS Sierra
Xcode : Xcode 9.2 Build version 9C40b
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : legacy
感谢您的帮助
通过添加新的webpack.config.js
:
// package.json
{
"config": {
"ionic_webpack": "./webpack.config.js"
},
}
and on ./webpack.config.js我刚刚复制了webpack.config.js的原始内容,并添加了以下行:
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
module: 'empty' // This line was added
}