Next.js Discord

Discord Forum

Create '.mjs' instead '.js'. Why does it happens?

Unanswered
Treeing Tennessee Brindle posted this in #help-forum
Open in Discord
Treeing Tennessee BrindleOP
Why does it happens when I create a new nextjs14 and then I got files with an ext .mjs instead .js like postcss.config.mjs and next.config.mjs ?

7 Replies

Golden northern bumble bee
.mjs represents module format so they use javascript modules. Its just a way of being explicit about the type of module that file will use

https://dev.to/nipu/js-cjs-and-mjs-defference-5f21
Treeing Tennessee BrindleOP
Yeah, but before I always got .js while creating a new project with nextjs14 and now i keep getting with .mjs, i don't know if it's default from nextjs14 install
Golden northern bumble bee
my best guess is they changed the default - are you running into issues or just curious?
Treeing Tennessee BrindleOP
i am running into issues, i don't wanna any files with .mjs for my project
They did change to mjs recently, what issue are you facing?
the mjs file format is basically what your js file in the project use, just that they are parsed by SWC and are 'module' by default
However the config used to use cjs instead so now with this change both your project and the config use module js (import instead of require () for example)