Webpack4 fix for .mjs files

amythical

amythical

Posted on May 18, 2024

Webpack4 fix for .mjs files

Using CRA and Webpack4 and find .mjs files giving an issue? (Yes im using CRA and Webpack4 in 2024 FML!)
Here are webpack config settings that will help -

const  reScript = /\.(js|jsx|mjs)$/;
resolve: {

// Allow absolute paths in imports, e.g. import Button from 'components/Button'
// Keep in sync with .flowconfig and .eslintrc
modules: ['node_modules', 'src'],
extensions: ['.js', '.jsx','.mjs']
},

module: {
// Make missing exports an error instead of warning
strictExportPresence:  true,
rules: [
{ 
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},

// Rules for JS / JSX
{
test:  reScript,
include: [SRC_DIR, resolvePath('tools')],
loader:  'babel-loader',
options: {} 
}
}],
Enter fullscreen mode Exit fullscreen mode

Cheers. Happy hacking!

Cover image credits - https://unsplash.com/photos/text-KZcWygxZ_J4

💖 💪 🙅 🚩
amythical
amythical

Posted on May 18, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Webpack4 fix for .mjs files
react Webpack4 fix for .mjs files

May 18, 2024