Closed doodlewind closed 1 year ago
Hi,
This is on purpose for https://github.com/lorenzofox3/zora/issues/155. If that causes trouble to your tool, you should probably directly import the es file which you can easily do with
import {test} from 'zora/es';
@3cp any comment ?
It's unfortunate that it broke vite.
As far as I knew, vite uses two different paths in dev and prod build. In dev build, vite uses esbuild. But in prod build, vite uses rollup.
May I ask does this issue appear in both dev and prod mode? Or just the prod mode?
Another thought is that importing cjs into esm code is well supported by Nodejs, it might be a reasonable feature to ask vite to support it. Both esbuild and rollup are capable to turn cjs code into esm.
I reopen the PR then, the time we figure out what's the best approach
Hello, I have an issue too after used the new esm typescript tsconfig:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}
After that i have a transpile issue cause zora types are not found anymore.
I found a fix modifying zora package.json like explained here:
I replaced
{
"name": "zora",
"version": "5.1.0",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./es.js",
"require": "./dist/index.cjs"
},
"./cjs": "./dist/index.cjs",
"./es": "./dist/index.js"
},
}
with (for my ESM need):
{
"name": "zora",
"version": "5.1.0",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/zora.d.ts",
"default": "./es.js"
},
"require": "./dist/index.cjs"
},
},
}
closed in favor of #170
The current default ESM entry in zora is
./es.js
, which resolves to thedist/index.cjs
bundle. But that is a CommonJS bundle, which doesn't work with Vite. Yet I found another correct setup is also defined in currentpackage.json
, which resolvesimport 'zora/es'
statement todist/index.js
, this works well.So currently for importing zora in Vite, user needs to alias
"zora"
to "zora/es". This PR is a simple fix.Current config pasted here: