Open Tapokj opened 11 months ago
Would love a fix for this as well
Hey! Out of curiosity, do you have an example project or repository we could clone to take a look at this? 🙏
Having similar issue:
node:internal/modules/cjs/loader:598
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/circleci/repo/node_modules/got-scraping/package.json
Hey @Tsopic I'm not sure that is an identical error to the reported error in this issue thread. The module is now ESM only (read more about what that implies from Sindre's gist https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
@FranciscoPinho @Tapokj poling again! Would love a reproduction sample we can use so I can investigate and let you know the next steps to do!
Had the same error earlier,
Added these lines to jest.config.ts
moduleNameMapper: {
"got-scraping": "<rootDir>/node_modules/got-scraping/dist/index.js",
},
But it's still whiny about the issue above. Probably is same error.
For further context, with the jest.config.ts in place. The error happens after building it into CommonJS, where the build succeeds but upon running the code it fails to find the module.
The reason seems to be that it's built into the not allowed require style const gotScraping = require("got-scraping")
using node v20
Did not have the issue with the earlier version of node did a bunch of package upgrades and node base version upgrade, and now it seems to be one of few packages with such issue.
got-scraping, like it's core dependency got, are now ESM only. That means you cannot use require to import the module, but need to either use ESM or use await import('got-scraping')
in an async context (see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c !!) 👀
If that's an issue with your current setup, you'll need to stick to versions before 4.x, but those versions are not getting new updates
Here's an example repo you can clone: https://github.com/dotspencer/jest-got-scraping/tree/ts
The main
branch is js and works.
But if you jump to the ts
branch, it fails in this way.
Test suite failed to run
Cannot find module 'got-scraping' from 'src/test.ts'
> 1 | import { gotScraping } from 'got-scraping';
Hello! I encountered the following error, using jest and typescript. Cannot find module 'got-scraping' from 'src/shared/extractor/html-loader.ts'
As you can understand, I have module that works in application well, but inside jest it causes a lot of pain. My version of got-scraping from package.json
"got-scraping": "^4.0.3",
All esm modules inside project works fine, so I doubt wrong configuration, as well I tried to map module for jest using moduleNameMapper option, but it wasn't successful.
"jest": "^29.7.0",
Jest version as well.My jest config:
Cheers!