Typescript issue ERR_PACKAGE_PATH_NOT_EXPORTED
xcarpentier opened this issue · comments
Seems to not working with typescript anymore ?
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/XXX/quick-start/node_modules/chevrotain/package.json
@xcarpentier Which version of chevrotain are you pulling? This should be resolved with the latest version.
Thanks @msujew for your reply.
I tried with the latest 11.0.3
.
I downgraded to the 10.5.0
without issue.
Oh, wait. Your typescript
version complains that there's no main
export defined. Could it be, that your TypeScript compiler version is kind of ... very old? Note that Chevrotain has dropped the CJS support with version 11, so it might be that it doesn't even run in your project without a special bundling setup.
The Typescript version is 5.3.3
.
You can see my project it here
When I changes the version to latest that's not working anymore, test failed because not finding chevrotain
package.
It's likely due to this config:
Since Chevrotain is ESM only, it cannot be imported as commonjs. TypeScript will attempt to do that and fail.
Do you have any example of configuration on github
. I'm not able to make it work with 11 version :/ ?
@xcarpentier We use Chevrotain@11 in Langium, see here for our config.
@xcarpentier - were you able to get this working? We are having the same issue. Switching out to a very custom tsconfig is generally undesirable and also causes TS to complain a lot when following the base examples from the quick start guide.
Switching out to a very custom tsconfig is generally undesirable
@gentle-noah Note that nothing Chevrotain requires is in any way special. ESM seems to be the way forward for most packages and the required tsconfig settings to import ESM code have been available for years now.
Aside from that, can you provide a reproducible example to showcase the issue you're experiencing?
@xcarpentier By the way, I've taken another look at your repo. The issue doesn't seem to be that TypeScript complains about chevrotain, but rather that your JavaScript code isn't able to run require('chevrotain')
. Which is expected, given that Chevrotain cannot be imported in cjs contexts. You need to use import * as chevrotain from 'chevrotain'
and start node with the --module
option (or set "type": "module"
in your package.json).
For anyone that stumbled on this issue, ee ended up just adopting v10.5 and everything works great. Having to juggle ESM only in more complex stacks like one built in an NX monorepo leads to too many TS and import issues. Being able to avoid dynamic imports also decreased parsing time from ~2.1s to 28ms on average.