Closed poisoncat closed 2 years ago
The temporary workaround I came up with was to change '.' to './index.js' for the time being but this is a generated file so not sure how to fix in the source itself.
Could you share the TypeScript version you are using?
Hi, the TypeScript version I'm using is the latest 4.7.4
Same version, tsconfig.json
is set so that it should be producing js files with es6 imports.
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"lib": ["ES2022"],
"moduleResolution": "Node16",
"rootDir": ".",
"outDir": "build",
"allowSyntheticDefaultImports": true,
"importHelpers": true,
"alwaysStrict": false,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"esModuleInterop": true,
"allowJs": true
},
"include": ["src/**/*", "__tests__/**/*"]
}
My tsconfig.json
file looks like this, but the compiler still throws the same error.
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "node16",
"rootDir": ".",
"outDir": "build",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"importHelpers": true,
"alwaysStrict": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"esModuleInterop": true,
"allowJs": true
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*", "__tests__/**/*"
]
}
Thanks for sending this by — the import should be updated to conform with ESM. I will make sure this is covered in the next release.
As a workaround, I recommend you to add the following to your tsconfig.json
s compilerOptions
:
{
"compilerOptions": {
"paths": {
"cheerio": [
"./node_modules/cheerio/lib/index.d.ts"
]
}
}
}
This will use cheerio
s cjs
types instead of the esm
types.
The type declarations look exactly the same so it fits as a workaround replacement perfectly well.
I got this error when I changed moduleResolution from 'node' to 'node16' in my tsconfig.json. I had to do this for the 'file-type' library, so between a rock and a hard place.
@manuth's workaround helped, thanks.
This still occurs with rc-12. I needed to go back to rc-10, to resolve this. Any clues?
Any update?
As a workaround, I recommend you to add the following to your
tsconfig.json
scompilerOptions
:{ "compilerOptions": { "paths": { "cheerio": [ "./node_modules/cheerio/lib/index.d.ts" ] } } }
This will use
cheerio
scjs
types instead of theesm
types. The type declarations look exactly the same so it fits as a workaround replacement perfectly well.
When use tsx
modules, error: ReferenceError: _default is not defined
As a workaround, I recommend you to add the following to your
tsconfig.json
scompilerOptions
:{ "compilerOptions": { "paths": { "cheerio": [ "./node_modules/cheerio/lib/index.d.ts" ] } } }
This will use
cheerio
scjs
types instead of theesm
types. The type declarations look exactly the same so it fits as a workaround replacement perfectly well.
This worked great until I migrated my monorepository to use pnpm. Now it got really nasty.
{
"compilerOptions": {
"paths": {
"cheerio": ["../../../node_modules/.pnpm/cheerio@1.0.0-rc.12/node_modules/cheerio/lib/index.d.ts"]
}
}
}
It looks like the -rc12
release is from before the fix.
It looks like the
-rc12
release is from before the fix.
I can confirm. -rc12
does not contain the fix. You need to roll back to rc-10
as @andreash mentioned.
when I use cheerio in my project with typescript, and try to compile it by
tsc
. The compiler throws an exception described below:This seems to be a bug in the package itself. How should I solve this problem? Thanks.
And I only use cheerio in my project like this:
"cheerio": "^1.0.0-rc.12" "@types/cheerio": "^0.22.31" node v16.16.0 npm v8.16.0