question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module not found error when bundling with Webpack 5

See original GitHub issue

Describe the bug I am unable to start a webpack dev server due to imports in .mjs files not having file extensions. The errors I get are:

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 34:0-49
Module not found: Error: Can't resolve './graphql' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'graphql.js'?
BREAKING CHANGE: The request './graphql' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 36:0-47:50
Module not found: Error: Can't resolve './type' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './type' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 49:0-53:205
Module not found: Error: Can't resolve './language' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './language' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 55:0-101
Module not found: Error: Can't resolve './execution' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './execution' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 56:0-68
Module not found: Error: Can't resolve './subscription' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './subscription' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 58:0-60:675
Module not found: Error: Can't resolve './validation' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './validation' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 62:0-64
Module not found: Error: Can't resolve './error' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './error' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

ERROR in ./node_modules/@aws-amplify/pubsub/node_modules/graphql/index.mjs 64:0-98:42
Module not found: Error: Can't resolve './utilities' in '/Users/mike/Projects/reactTemplate/node_modules/@aws-amplify/pubsub/node_modules/graphql'
Did you mean 'index.js'?
BREAKING CHANGE: The request './utilities' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js 90:0-39 221:41-53 345:49-61 501:37-49 517:46-58 541:37-49
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js 15:0-45 15:0-45
 @ ./node_modules/@aws-amplify/pubsub/lib-esm/index.js 14:0-28 14:0-28
 @ ./node_modules/aws-amplify/lib-esm/index.js 27:0-45 27:0-45
 @ ./src/index.jsx 3:0-34 6:0-17

webpack 5.6.0 compiled with 8 errors and 30 warnings in 14515 ms
ℹ 「wdm」: Failed to compile.

To Reproduce

git clone https://github.com/mmykhaylov/amplifyWebpack5Demo.git
yarn install
yarn dev

Look at the console and see 30 warnings and 8 errors

Expected behavior Build runs without errors or warnings

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:27 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
jiyoon-koocommented, May 13, 2021

@rudyhadoux the workaround was implemented in webpack.config.ts under rules section, like this

...

module.exports = {
  mode: 'none',
  entry: './src/index.tsx',
  ...
  module: {
    rules: [
      // TODO: Remove the below rule for .mjs, once aws-amplify supports webpack 5
      {
        test: /\.m?js/,
        resolve: {
            fullySpecified: false
        }
      },
      ...
5reactions
fabien-lgcommented, Jul 2, 2021

Solution for Quasar. Add in quasar.conf.js

chainWebpack (chain) {
        chain
          .module
          .rule('esm')
          .test(/\.m?jsx?$/)
          .resolve.set('fullySpecified', false)
      },
Read more comments on GitHub >

github_iconTop Results From Across the Web

'Module not found' error when running webpack - Stack Overflow
If you're running it with local webpack try this: delete packages and install and run. npm cache verify npm install. Share.
Read more >
Externals - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
webpack module not found: error: can't resolve 'fs' - You.com
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable...
Read more >
Webpack and Jest v0.36 Upgrade Guide
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js ... Compiled with problems: Error: Module not found: Error: Can't resolve ......
Read more >
Next.js + Webpack - Fix for ModuleNotFoundError: Module not ...
To fix the error with Webpack 5, update your Next.js config file ( /next.config.js ) with the following, it tells webpack not to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found