Skip to content

Default to ES modules #1214

Open
Open
@matthew-white

Description

@matthew-white

While working on #671, I noticed that when you create a new Vue project using Vite, it specifies "type": "module" in package.json. When I do so in Frontend, most things work. However, testing does not:

  • karma.conf.js throws an error about the use of require.
  • I'm not able to replace require with import for the following line:
    const webpackConfig = require('./node_modules/@vue/cli-service/webpack.config.js');
  • I tried to rename karma.conf.js to karma.conf.cjs, but that didn't work.

Therefore, I think this issue is blocked by #1211. However, I think we should make this change once #1211 is resolved. It'd be really nice for the scripts in bin/ to use ES modules instead of CommonJS. I've had trouble importing files from src/ into bin/. I suspect that once the scripts in bin/ are using ES modules, we'll be able to deduplicate/refactor some code (though that's outside the scope of this issue).

I think this is what we need to do:

  • Add "type": "module" to package.json.
  • Replace require with import in bin/, and replace module.exports with export.
  • Rename .eslintrc.js to .eslintrc.cjs.
  • Update npm run lint and npm run lint:fix to include .cjs files.

Metadata

Metadata

Assignees

Labels

infrastructureChanges to core libraries or setup

Type

No type

Projects

Status

🕒 backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions