You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
After several hours of debugging I've managed to work out why the Jest 22 upgrade PR was failing when Jest was used with Preact, but not when used with React.
When reproducing locally (inside a project created with create-project), the failure looked like:
test-preact-jest $ yarn test
yarn run v1.6.0
$ neutrino test
FAIL test\simple_test.js
● Test suite failed to run
TypeError: Cannot read property 'AsymmetricMatcher' of undefined
at Object.<anonymous> (../neutrino-dev/node_modules/jest-matcher-utils/build/index.js:31:49)
at Object.<anonymous> (../neutrino-dev/node_modules/expect/build/index.js:3:25)
The cause was this:
jest-matcher-utils (used by jest and present in the yarn linked jest preset directory) uses pretty-format, which gets hoisted to the node_modules in the monorepo root
preact-compat (which is in the test project's node_modules) indirectly uses a much older version of pretty-format, which gets hoisted to the root of the test project's node_modules
because of the current Neutrino resolve.modules settings, jest-matcher-utils ended up using the older pretty-format from the test project node_modules instead of the monorepo node_modules
Doing a yarn test --debug showed the generated modules list being passed to Jest, as:
Doing any of the following stopped the test from failing:
Moving "C:\\Users\\Ed\\src\\neutrino-dev\\node_modules" higher up the list (by making the corresponding monorepo-specific call in the web preset a .prepend())
Removing "C:\\Users\\Ed\\src\\test-preact-jest\\node_modules" (by removing the .add(neutrino.options.node_modules) from the web preset)
Removing all entries other than node_modules (the webpack default). This surprisingly worked for both test & build.
It also seems wrong to not have node_modules as the first entry?
I'll probably end up picking (1) or (2) as a workaround for now (since it will prevent any risk to non-monorepo), however I think we really need to come up with a better order/approach here (within the constraints of having to work with monorepo + standalone + standalong w/no hoisting), since this is not the first time I've spent hours debugging an issue to find it's been due to the Neutrino modules resolution order (another example).
The text was updated successfully, but these errors were encountered:
Since the custom module resolution is not required, and has been the
cause of at least 3 bugs that I have spent hours debugging.
The vast majority of modules referenced by Neutrino already use
`require.resolve()` and so are unaffected by this change. Those that
do not (for example eslint presets, since eslint doesn't support
specifying them as full paths), were not helped by this custom
module resolution anyway, since the resolution happens outside of
webpack, and so relied on hoisting even before this change.
The `node_modules` option has been removed in favour of using the
Neutrino API (or else `NODE_PATH`). Customising module resolution
is a massive footgun and should not be used in most cases.
Fixes#822.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
After several hours of debugging I've managed to work out why the Jest 22 upgrade PR was failing when Jest was used with Preact, but not when used with React.
When reproducing locally (inside a project created with
create-project
), the failure looked like:The cause was this:
jest-matcher-utils
(used by jest and present in the yarn linked jest preset directory) usespretty-format
, which gets hoisted to the node_modules in the monorepo rootpreact-compat
(which is in the test project's node_modules) indirectly uses a much older version ofpretty-format
, which gets hoisted to the root of the test project'snode_modules
resolve.modules
settings,jest-matcher-utils
ended up using the olderpretty-format
from the test projectnode_modules
instead of the monoreponode_modules
Doing a
yarn test --debug
showed the generated modules list being passed to Jest, as:Doing any of the following stopped the test from failing:
"C:\\Users\\Ed\\src\\neutrino-dev\\node_modules"
higher up the list (by making the corresponding monorepo-specific call in the web preset a.prepend()
)"C:\\Users\\Ed\\src\\test-preact-jest\\node_modules"
(by removing the.add(neutrino.options.node_modules)
from the web preset)node_modules
(the webpack default). This surprisingly worked for both test & build.It also seems wrong to not have
node_modules
as the first entry?I'll probably end up picking (1) or (2) as a workaround for now (since it will prevent any risk to non-monorepo), however I think we really need to come up with a better order/approach here (within the constraints of having to work with monorepo + standalone + standalong w/no hoisting), since this is not the first time I've spent hours debugging an issue to find it's been due to the Neutrino modules resolution order (another example).
The text was updated successfully, but these errors were encountered: