Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare "type": "module" in templates. #4535

Closed
4 tasks done
junaga opened this issue Aug 7, 2021 · 1 comment
Closed
4 tasks done

Declare "type": "module" in templates. #4535

junaga opened this issue Aug 7, 2021 · 1 comment
Labels
duplicate This issue or pull request already exists enhancement: pending triage wontfix This will not be worked on

Comments

@junaga
Copy link
Contributor

junaga commented Aug 7, 2021

Clear and concise description of the problem

Vite is all about es modules. Imagine you run node vite.config.js with the following file, it won't work:

// vite.config.js
import vuePlugin from "@vitejs/plugin-vue"

console.log(vuePlugin())

You do this, to get a sense of how Vite plugins (their API) work.

But it fails, because it uses import syntax. node by default expects commonJS. This applies to all other scripts .js in the project. You write some es6-es2021 code and it works on the client, but doing node script.js fails by default. Is this to scare off newbies?

Suggested solution

Adding "type": "module" to the package.json in scaffoldings makes more sense I think.

Alternative

No response

Additional context

No response

Validations

@Shinigami92
Copy link
Member

Shinigami92 commented Aug 8, 2021

Duplicate of #4293

Workaround: use vite.config.ts instead of .js
vite.config.mjs may also work

@Shinigami92 Shinigami92 added duplicate This issue or pull request already exists wontfix This will not be worked on labels Aug 8, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists enhancement: pending triage wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants