json-diff-kit icon indicating copy to clipboard operation
json-diff-kit copied to clipboard

Error `Unexpected token 'export'` when using with Remix/Vite

Open valdineifer opened this issue 8 months ago • 0 comments

I'm getting this error when using this package with Remix/Vite. I only fixed this error with one of these actions:

  • adding "type": "module" in the package.json of this npm package;
  • adding the module (as string json-diff-kit) to the ssr.noExternal array in vite.config.ts (i think this option may affect performance).

Update: Actually, I think that the second option doesn't works, because now I'm getting another error: document is not defined, possibly due to SSR. Update 2: I used the Suspense element from React and it solved the document error.

I created this issue because I think that it doesn't seems to be right do one of these things to get this package to work, instead of the common way: install->import->usage.


Details of the error:

19:37:18 [vite] Error when evaluating SSR module virtual:remix/server-build: failed to import "...myfile..._.$id.tsx"
|- ~/myprojectfolder/node_modules/json-diff-kit/dist/index.js:1
export { default as Differ } from './differ.js';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:356:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:305:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

valdineifer avatar Jun 02 '24 23:06 valdineifer