Skip to content
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

Every package whose major version larger than 6 is not work #195

Closed
libin-code opened this issue Aug 22, 2023 · 10 comments
Closed

Every package whose major version larger than 6 is not work #195

libin-code opened this issue Aug 22, 2023 · 10 comments

Comments

@libin-code
Copy link

"I recently installed the yeoman-test@7 package in my local environment and used Jest to test my project. However, I encountered the following Jest error: 'Cannot find module 'yeoman-test' from '.

Upon investigation, I discovered that the yeoman-test package no longer includes the main field in its package.json file starting from version 6.3.0. This causes Jest to be unable to locate the entry file, as it is now stored in the dist directory.

Could you please address this issue and provide a fix?

@iamdavidjackson
Copy link

I encountered this problem today too and went down a bit of a rabbit hole. It seems that the problem is more with Jest than it is with Yeoman-test. Yeoman-test relies on mem-fs which in turn relies on textextensions which uses the same package definitions yeoman-test so it will break there too. It has something to do with the resolve module that Jest uses. The way I solved it was to use Mocha for the generator tests and Jest for my other unit tests. I used .spec for mocha tests and .test for Jest ones and it works fine. Not a solution but a workaround. Hope that helps!

@mshima
Copy link
Member

mshima commented Sep 21, 2023

I have been using latest beta with vitest (threads needs to be disabled) and mocha.
I've never used jest with yeoman projects. IMO jest is too bloated for node projects and brings poor support for esm.

@Enet4
Copy link

Enet4 commented Sep 26, 2023

This may well have to do with the transition to ECMAScript modules. Jest itself claims that support for ESM is still experimental, and it does take going through a few hoops to get existing Node.js code to run, especially if not all code is ready to be migrated to use ECMAScript modules exclusively.

@libin-code
Copy link
Author

I encountered this problem today too and went down a bit of a rabbit hole. It seems that the problem is more with Jest than it is with Yeoman-test. Yeoman-test relies on mem-fs which in turn relies on textextensions which uses the same package definitions yeoman-test so it will break there too. It has something to do with the resolve module that Jest uses. The way I solved it was to use Mocha for the generator tests and Jest for my other unit tests. I used .spec for mocha tests and .test for Jest ones and it works fine. Not a solution but a workaround. Hope that helps!

Thanks for the reply, actually I don't understand why mocha will work because I think if the author didn't point to the main field in the package.json file and no index.js or index.node file in the root directory, npm can't find the module. That's why yeoman-test@6.3.0 worked in my case but others did not work.

I think it's strange, do you have any other clue? :think:

@ystxn
Copy link

ystxn commented Oct 25, 2023

mocha doesn't even work for me. why was the main field removed?

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/user/project/node_modules/yeoman-test/package.json
    at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:362:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:642:13)
    at resolveExports (node:internal/modules/cjs/loader:567:36)
    at Module._findPath (node:internal/modules/cjs/loader:636:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1063:27)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/home/ys/code/generator-symphony/test/app.spec.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

@mshima
Copy link
Member

mshima commented Oct 26, 2023

This package is ESM only package now. You should update your packages according to ESM migration.
main fields is not required for ESM packages.
Closing.

@mshima mshima closed this as completed Oct 26, 2023
@mshima
Copy link
Member

mshima commented Oct 26, 2023

For jest 29, ESM packages should be added to transformIgnorePatterns.
Maybe jest 30 brings out of the box ESM support.

@ystxn
Copy link

ystxn commented Oct 26, 2023

I think there's a severe lack of documentation that describes this breaking change and what developers should do to upgrade. Please add concrete examples to your documentation that address how to get started with mocha or jest, since both do not work with the latest yeoman-test without custom configuration.

@mshima
Copy link
Member

mshima commented Oct 26, 2023

mocha works out-of-the-box using this example https://github.com/yeoman/yeoman-test/blob/main/README.md#usage.

@mshima
Copy link
Member

mshima commented Oct 26, 2023

@ystxn please look what ESM/ECMAScript migration means, your generator is CJS https://github.com/finos/generator-symphony/blob/master/test/app.spec.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants