Fixed!

This problem was very similar to https://github.com/webpack/webpack/issues/11467.

So I merely had to add this to webpack.config.js (under module and rules):

      {
        test: /\.m?js/,
        resolve: {
          fullySpecified: false
        }
      }

particular addition..

If you used npx create-react-app my-app --template typescript to create your app, then complete solution is to rewire your create-react-app project and add custom settings for your webpack without eject :

  1. Install react-app-rewired

For create-react-app 2.x with Webpack 4:

npm install react-app-rewired --save-dev

For create-react-app 1.x or react-scripts-ts with Webpack 3:

npm install [email protected] --save-dev
  1. Create a config-overrides.js file in the root directory

like this:

+-- your-project
|   +-- config-overrides.js
|   +-- node_modules
|   +-- package.json
|   +-- public
|   +-- README.md
|   +-- src

fill it with this code:

module.exports = function override(config, env) {
    // New config, e.g. config.plugins.push...

    config.module.rules = [...config.module.rules, 
        {
            test: /\.m?js/,
            resolve: {
              fullySpecified: false
            }
        }
      ]

    return config
}
  1. 'Flip' the existing calls to react-scripts in npm scripts for start, build and test

from:

/* package.json */

  "scripts": {
   "start": "react-scripts start",
   "build": "react-scripts build",
   "test": "react-scripts test",
   "eject": "react-scripts eject"
}

To:

/* package.json */

  "scripts": {
   "start": "react-app-rewired start",
   "build": "react-app-rewired build",
   "test": "react-app-rewired test",
   "eject": "react-scripts eject"
}

Note: Do NOT flip the call for the eject script. That gets run only once for a project, after which you are given full control over the webpack configuration making react-app-rewired no longer required. There are no configuration options to rewire for the eject script.

  1. Start the Dev Server
npm start
  1. Build your app
npm run build