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

Problem with "type" : "module" option in package.json #61

Closed
cimchd opened this issue Jun 27, 2021 · 4 comments · Fixed by #89
Closed

Problem with "type" : "module" option in package.json #61

cimchd opened this issue Jun 27, 2021 · 4 comments · Fixed by #89

Comments

@cimchd
Copy link
Contributor

cimchd commented Jun 27, 2021

I have a project with es modules enabled in the package.json.

// package.json
{
  "name": "project",
  "type": "module",
  "dependencies:  {
    ...
  }
   ...
}

I ran the command vite-ssg buildand got the following errot: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

I figured out the problem is that the generated file in the .vite-ssg-temp folder is a common.js file with file ending .js. I changed the file ending to .cjs and it worked for me.

@cimchd
Copy link
Contributor Author

cimchd commented Jul 14, 2021

Added a pull request how I solved it in vite-ssg as an option without breaking changes.

@cimchd
Copy link
Contributor Author

cimchd commented Aug 22, 2021

In the meantime i canceled my pr from above and instead changed the rollup options in node/build.ts to use .cjs instead of .js :

      rollupOptions: {
        output: {
          entryFileNames: '[name].cjs',
        },
      },

If you want me to create a pr, just let me know.

@antfu
Copy link
Member

antfu commented Aug 22, 2021

That looks like a much better solution, PR welcome 👍 (we could do that without an option but check the package.json directly)

@cimchd
Copy link
Contributor Author

cimchd commented Aug 22, 2021

Good idea. I used read-pkg-up package to determine the nearest package.json file. So we should not need an option for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants