未捕获错误:在Ionic App上找不到模块“module”

时间:2018-02-10 19:52:45

标签: node.js ionic-framework npm webpack ionic2

我刚刚将我的离子应用程序升级到最新版本,该应用程序正确编译但在执行时我收到以下错误:

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

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

通过添加新的webpack.config.js

解决
// package.json
{
    "config": {
        "ionic_webpack": "./webpack.config.js"
    },
}

在./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
}