babel / babel/babel-loader

Error when try to use .mjs babel.config.mjs file

Open
#953 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.8k
Forks
456
Avg merge
9h 19m
Merged PRs (30d)
2

Description

**I'm submitting a bug report**

**Webpack Version:**
5.74.0

**Babel Core Version**:
7.19.1

**Babel Loader Version**:
8.2.5

**Please tell us about your environment:**
OSX 10.x

**Current behavior:**
I am converting my project's config from .js to .mjs and I'm getting the following error:
Cannot change caching after evaluation has completed.

**Expected/desired behavior:**
Expect to be able to just replace .js extension with .mjs and everything to work as before (with changing imports/exports to mjs)

So my babel configuration file is now named babel.config.mjs
```
export default function(api) {

// any attempt to use anything here from api fails with the following message:
// Cannot change caching after evaluation has completed.

// return usual things
}
```
Webpack configuration is pretty standard (.js extension) but the concerning block is like this:
```
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
},
},
],
},

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with babel.config.mjs and the shown webpack configuration using babel-loader. Start by tracing what happens when the exported config function accesses api, then compare it with the .js configuration behavior. Done means the .mjs configuration can use the same api interactions without triggering “Cannot change caching after evaluation has completed.”

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.