DEV Community

Cover image for Webpack4 fix for .mjs files
amythical
amythical

Posted on

5

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay