.mjs node module not working after eject
Created by: 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
-
node -v
: v8.2.1 -
npm -v
: 5.3.0 -
yarn --version
(if you use Yarn): 0.27.5 -
npm ls react-scripts
(if you haven’t ejected): [ejected]
Then, specify:
- Operating system: Mac OS X High Sierra
- Browser and version (if relevant): Chrome Version 62.0.3202.94 (Official Build) (64-bit)
Steps to Reproduce
(Write your steps here:)
- Use create-react-app to create a new react app
- Eject the react app
- Install "Universal Router" using yarn (
yarn add universal-router
) - 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
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.