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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs