-
Notifications
You must be signed in to change notification settings - Fork 80
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
CJS / ESM conflict #230
Comments
@brunnerh I don't have time right now to try to reproduce this, but I'm aware of this type of cjs/esm import conflict. Thankfully, |
|
@kaisermann Works for me now. |
@softwarecurator can you share a minimal repro or, if not, more details about your environment? |
works with 3.7.3 for me, but not with 3.7.4 |
@kaisermann You can take this repo at this commit: Pierstoval/aerg@3f668c2 , just do "yarn install" then "yarn build" to build the app, and you'll see the error:
|
@Pierstoval The loaded file is the ES module ( I tried to install and use v3.7.4 in my local SvelteKit test project and it works just fine. |
I must happen to have certain dependencies of the project that make this not work properly. Maybe it's how locale is set, I don't know, I will try to investigate further |
same not sure what is causing it, will stay on lower version for now though |
Apparently it's caused when building with the I created a super slight reproducer: https://github.com/pierstoval/svelte-i18n-reproducer What's been done in this:
To reproduce the bug, install the project via
|
I am using |
i'm using vercel-adapter and getting it |
this is a breaking change for |
It's been breaking either way; for me since 3.4.0. You should be able to make Vite's SSR work by adding this to the export default defineConfig({
// ...
ssr: {
noExternal: [
'intl-messageformat',
'@formatjs/icu-messageformat-parser',
'@formatjs/icu-skeleton-parser',
],
},
});
There are also options related to optimization that could be relevant; there is a note regarding ESM modules referencing CJS modules. (Tried a few things there, but it did not seem to matter.) Rather annoying that this doesn't "just work". As noted, both packages in theory support both module types. @oyvindo found another fix/workaround (#232):
Tested that and it seems to work, the reason is beyond me... |
Maybe a dumb idea but could it be that it's a wrong version of intl-messageformat set in package.json? If i install intl-messageformat locally it installs version 10.15.x and everything works. The package.json of svelte-i18n has 9.x.x as a dependency and the install leads to this error. I mean:
|
I spent hours looking at different versions of the package and the behavior made no sense to me at all. After seeing in #232 that installing the latest version fixed this, I went through the various 10.x.x versions to see what change might have caused the fix and it started to work at v.10.1.2 which is a completely broken release that only contains the raw source. Later versions like v.10.1.3 appear to work as well, meanwhile the changelog is useless for those versions: Changelog Snippet
Also, a locally installed v.10 should not even be used as far as I understand it, as the version specified by |
Maybe there's some kind of problem in module resolution that makes a local install of v10 supersede |
I recommend using publint to diagnose issues like these: https://publint.dev/svelte-i18n@3.7.4 Also, given that this is a Svelte-specific library, there's really no reason to have a CJS build. The best solution would be to drop the CJS version which would simplify things a fair amount |
Except that you might want to use the library on a Node server, so you don't have to use another library to do the same thing you already do on the client. Which is exactly what I do. |
ESM runs on the server as well. All SvelteKit projects have been ESM-only since day 1. Svelte 4 only outputs ESM. Vite is dropping CJS support for the server in Vite 5 to be released shortly and 70% of Svelte users use Vite. CJS support in Svelte is basically dead at this point. If you still need it for some reason you can always import the library as ESM and then bundle your project to CJS. |
I made some change in PR #220 so it could solve this issue. |
I've released I've tested it with the repo made by @Pierstoval and the build is passing and the preview working |
BREAKING CHANGE: package is now esm-only * chore(deps-dev): bump postcss from 8.4.29 to 8.4.31 Bumps [postcss](https://github.com/postcss/postcss) from 8.4.29 to 8.4.31. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](postcss/postcss@8.4.29...8.4.31) --- updated-dependencies: - dependency-name: postcss dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * fix #230 : CJS / ESM conflict --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
From #209 (comment)
What I observed appears to have a different source. Somehow the modules are resolved the wrong way.
My application's import resolves to
node_modules/svelte-i18n/dist/runtime.cjs.js
which has:But the
require('intl-messageformat')
is resolved in such a way, thatIntlMessageFormat
is an object with adefault
property which contains the actual class, so thenew IntlMessageFormat
/IntlMessageFormat.resolveLocale
errors. There probably is some mixing of CJS and ESM going on (this is always such a pain).Unfortunately, I have not been able to create a minimal reproduction so far.
This should probably be tracked in a separate issue.
The logged errors could maybe be more generic, as these are lies:
Originally posted by @brunnerh in #209 (comment)
The text was updated successfully, but these errors were encountered: