Enable ES6 modules through setting "type": "module" in package.json
Rename babel.config.js to babel.config.cjs and vue.config.js to vue.config.cjs (do similar for others if applicable)
Add a system under test (e.g. App.vue) that uses top-level await.
Run npm run build -- --mode test
What is expected?
Successful build
What is actually happening?
Build fails
I have debugged this and it fails due to this code:
// Though in the vue-cli repo, we only use the two environment variables
// for tests, users may have relied on them for some features,
// dropping them may break some projects.
// So in the following blocks we don't directly test the `NODE_ENV`.
// Rather, we turn it into the two commonly used feature flags.
if (!process.env.VUE_CLI_TEST && process.env.NODE_ENV === 'test') {
// Both Jest & Mocha set NODE_ENV to 'test'.
// And both requires the `node` target.
process.env.VUE_CLI_BABEL_TARGET_NODE = 'true'
// Jest runs without bundling so it needs this.
// With the node target, tree shaking is not a necessity,
// so we set it for maximum compatibility.
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = 'true'
}
Version
5.0.8
Reproduction link
github.com
Environment info
Steps to reproduce
"type": "module"
in package.jsonnpm run build -- --mode test
What is expected?
Successful build
What is actually happening?
Build fails
I have debugged this and it fails due to this code:
Exactly this line is causing the error
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = 'true'
.Setting this variable forces
envOptions.modules = 'commonjs'
which breaks the project.My current workaround to add following to vue.config file to force if statement to be false:
Hope it helps others with same setup.