Skip to content

.mjs node module not working after eject #3520

Closed
@Kingdutch

Description

@Kingdutch

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Unsure, using yarn 0.27.5

Which terms did you search for in User Guide?

webkit, constructor

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_1_universal_router___default.a is not a constructor

Environment

  1. node -v: v8.2.1
  2. npm -v: 5.3.0
  3. yarn --version (if you use Yarn): 0.27.5
  4. npm ls react-scripts (if you haven’t ejected): [ejected]

Then, specify:

  1. Operating system: Mac OS X High Sierra
  2. Browser and version (if relevant):
    Chrome Version 62.0.3202.94 (Official Build) (64-bit)

Steps to Reproduce

(Write your steps here:)

  1. Use create-react-app to create a new react app
  2. Eject the react app
  3. Install "Universal Router" using yarn (yarn add universal-router)
  4. Add the following lines to your src/index.js
import UniversalRouter from 'universal-router';
console.log(UniversalRouter);
const router = new UniversalRouter([]);

Expected Behavior

The console output should show that UniversalRouter is a proper constructor function and no errors should occur.

Actual Behavior

The console outputs /static/media/browser.99d6d764.mjs and the following error is shown:
TypeError: __WEBPACK_IMPORTED_MODULE_1_universal_router___default.a is not a constructor

image

Possible fix

I found that the following fixed this for me:
On line 201 of the generated webpack.config.dev.js replace:
exclude: [/\.js$/, /\.html$/, /\.json$/],
with
exclude: [/\.m?js$/, /\.html$/, /\.json$/],

This might also need to be done for the .prod version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions