cm-chessboard icon indicating copy to clipboard operation
cm-chessboard copied to clipboard

Unable to build with Vite 3

Open ZetiMente opened this issue 2 years ago • 1 comments

(node:94053) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) /Users/zeti/Platform/games/node_modules/.pnpm/[email protected]/node_modules/cm-chessboard/src/cm-chessboard/Chessboard.js:7 import {ChessboardState} from "./model/ChessboardState.js" ^^^^^^

SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1033:15) at Module._compile (node:internal/modules/cjs/loader:1069:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at ModuleWrap. (node:internal/modules/esm/translators:170:29) at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:385:24) [SyntaxError: Cannot use import statement outside a module]

The repo: https://github.com/ZetiAi/games When doing pnpm build

This worked on Vite 2.

ZetiMente avatar Aug 06 '22 19:08 ZetiMente

This seems to be more of a Vite 3 issue, so you should report this to support there. 🤷‍♂️

shaack avatar Aug 07 '22 09:08 shaack

In my Vite 3 project I am able to to dev/build no problem. Using Vite 3.0.5

vesper8 avatar Aug 10 '22 00:08 vesper8

In my Vite 3 project I am able to to dev/build no problem. Using Vite 3.0.5

Could you share your repo? My impression was the current packaging wasn't compatible with Node.js. And that all the files were being treated as CommonJS unless "type": "module" is set in package.json or the files end with .mjs

ZetiMente avatar Aug 10 '22 16:08 ZetiMente

hmm okay, if I add "type": "module" in the package.json file, the error goes away.

ZetiMente avatar Aug 10 '22 16:08 ZetiMente

In the package.json of cm-chessboard? This could be easy added.

shaack avatar Aug 10 '22 16:08 shaack

In the package.json of cm-chessboard? This could be easy added.

yeah, it seems the issue is not vite 3 but Node 16.15.0. That would be great if you could add! 👍

ZetiMente avatar Aug 10 '22 16:08 ZetiMente

Fixed with version 5.0.1

shaack avatar Aug 10 '22 17:08 shaack

@shaack You're the man! Thank you!

ZetiMente avatar Aug 10 '22 17:08 ZetiMente