JohnnyAce
JohnnyAce

Reputation: 3749

Uncaught Error: Cannot find module "module" on Ionic App

I just upgraded my ionic app to the latest version, the app compiles correctly but on execution I get the following error:

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)

I traced back the error to this line on node_modules/require-from-string/index.js:

'use strict';

var Module = require('module'); // <--This line
var path = require('path');

It appears to me that something is not correctly configured on ionic but I can't seem to find what's the missing config. Since these module is part of node I don't know what could be happening.

The Ionic Information ionic info is:

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

Thanks for your help

Upvotes: 0

Views: 1599

Answers (1)

JohnnyAce
JohnnyAce

Reputation: 3749

Solved by adding a new webpack.config.js:

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

And on ./webpack.config.js I just copied the original contents of the webpack.config.js and added the following line:

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

Upvotes: 0

Related Questions