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

Cannot find module '../../jest.preset' on nx migrate latest #9973

Closed
justinhandley opened this issue Apr 23, 2022 · 5 comments · Fixed by #10035
Closed

Cannot find module '../../jest.preset' on nx migrate latest #9973

justinhandley opened this issue Apr 23, 2022 · 5 comments · Fixed by #10035
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@justinhandley
Copy link

Current Behavior

When running nx migrate latest to version 14.02 I get

Running migration update-jest-config-extensions
Cannot find module '../../jest.preset'

But it doesn't specify where it can't find it - I searched all instances of that and the all correctly pointed to a jest preset file in root.

Expected Behavior

One the migration, I expect it to work or give more useful feedback.

Steps to Reproduce

Just run nx migrate latest - but obviously the entire project structure isn't easy to replicate.

Failure Logs

Running migration update-jest-config-extensions
Cannot find module '../../jest.preset'
Require stack:

  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/jest/src/utils/config/functions.js
  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/jest/src/utils/config/update-config.js
  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/jest/index.js
  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/workspace/src/generators/library/library.js
  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/workspace/index.js
  • /Users/justinhandley/IdeaProjects/tmi-nx-stack/node_modules/@nrwl/angular/src/migrations/update-13-2-0/update-testing-imports.js
  • /private/var/folders/_4/fklvk31d4vx19g5pv24v9_6m0000gn/T/tmp-16188-69NU7hEDsV0X/node_modules/nx/src/command-line/migrate.js
  • /private/var/folders/_4/fklvk31d4vx19g5pv24v9_6m0000gn/T/tmp-16188-69NU7hEDsV0X/node_modules/nx/src/command-line/nx-commands.js
  • /private/var/folders/_4/fklvk31d4vx19g5pv24v9_6m0000gn/T/tmp-16188-69NU7hEDsV0X/node_modules/nx/bin/init-local.js
  • /private/var/folders/_4/fklvk31d4vx19g5pv24v9_6m0000gn/T/tmp-16188-69NU7hEDsV0X/node_modules/nx/bin/nx.js

Environment

NX Report complete - copy this into the issue template

Node : 16.10.0
OS : darwin x64
yarn : 1.22.17

nx : 14.0.2
@nrwl/angular : 14.0.2
@nrwl/cypress : 14.0.2
@nrwl/detox : 14.0.2
@nrwl/devkit : 14.0.2
@nrwl/eslint-plugin-nx : 14.0.2
@nrwl/express : Not Found
@nrwl/jest : 14.0.2
@nrwl/js : 14.0.2
@nrwl/linter : 14.0.2
@nrwl/nest : 14.0.2
@nrwl/next : Not Found
@nrwl/node : 14.0.2
@nrwl/nx-cloud : 13.3.1
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.0.2
@nrwl/react-native : 14.0.2
@nrwl/schematics : Not Found
@nrwl/storybook : 14.0.2
@nrwl/web : 14.0.2
@nrwl/workspace : 14.0.2
typescript : 4.6.3
rxjs : 6.5.5

Community plugins:
@nxpm/stack: 4.18.0

@chrislambe
Copy link

Very similar issue here, but the error is about jest.config instead of jest.preset:

Running migration update-jest-config-extensions
Cannot find module './jest.config'
Require stack:
- /path/to/project/node_modules/@nrwl/jest/src/utils/config/functions.js
- /path/to/project/node_modules/@nrwl/jest/src/migrations/update-14-0-0/update-jest-config-ext.js
- /private/var/folders/mb/cvyzfj3d7h73dtph7777yxqw0000gn/T/tmp-52964-pNxeFyaS3YIc/node_modules/nx/src/command-line/migrate.js
- /private/var/folders/mb/cvyzfj3d7h73dtph7777yxqw0000gn/T/tmp-52964-pNxeFyaS3YIc/node_modules/nx/src/command-line/nx-commands.js
- /private/var/folders/mb/cvyzfj3d7h73dtph7777yxqw0000gn/T/tmp-52964-pNxeFyaS3YIc/node_modules/nx/bin/init-local.js
- /private/var/folders/mb/cvyzfj3d7h73dtph7777yxqw0000gn/T/tmp-52964-pNxeFyaS3YIc/node_modules/nx/bin/nx.js

Environment

NX Report complete - copy this into the issue template

Node : 16.13.2
OS : darwin arm64
yarn : 3.1.0

nx : 14.0.3
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 14.0.3
@nrwl/eslint-plugin-nx : 14.0.3
@nrwl/express : Not Found
@nrwl/jest : 14.0.3
@nrwl/js : 14.0.3
@nrwl/linter : 14.0.3
@nrwl/nest : 14.0.3
@nrwl/next : Not Found
@nrwl/node : 14.0.3
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/workspace : 14.0.3
typescript : 4.5.5
rxjs : 7.4.0

Community plugins:

@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Apr 28, 2022
@barbados-clemens
Copy link
Contributor

@chrislambe @justinhandley
are those files being imported into your a project jest.config.js?

it looks to be related to how the migration updates the preset and so it requires reading your jest.config.js through runInContext call.

I'm updating this migration to not do this anymore as we actually don't need to update the preset property in the configs anymore.

this change is going to be a part of the change to module.exports => export default I'm working on. I was hoping to get something in draft today but ran into issues with updating tests to validate the new behavior. I hope to have something end of this week/early next week ready to be merged.

@viceice
Copy link
Contributor

viceice commented Apr 29, 2022

Can i simply manually do the migration? if i'm correct it only renames files from js to ts extension?

@justinhandley
Copy link
Author

So, for me it was that I was running react-native and the upgrade to 13 changed this

const workspacePreset = require('../../jest.preset')
module.exports = {
...workspacePreset,
displayName: 'native',
preset: 'react-native',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['/test-setup.ts'],
transform: {
'\.(js|ts|tsx)$': require.resolve('react-native/jest/preprocessor.js'),
'^.+\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve('react-native/jest/assetFileTransformer.js'),
},
}

to no longer use workspacePreset, but instead to use resolver: '@nrwl/jest/plugins/resolver',

But, the migration didn't remove the require at the top. I took that out and ran it again and it was fine.

barbados-clemens added a commit that referenced this issue May 11, 2022
…e `export default` (#10035)

* fix(testing): jest.preset.ts => jest.preset.js

* fix(testing): update to export default

* fix(testing): migration for moving to export default

* fix(testing): add eslint ignore comments for jest config properties

fixes: #10021

* fix(testing): update tsconfig.spec.json for next apps with project parserOptions

fixes: #9982

* fix(testing): prevent renaming root jest preset

fixes: #9973

* fix(testing): update snapshots for export default

* fix(testing): bump migration version to run

* fix(testing): make sure default jest tests pass for various projects

* fix(js): generate correct jest config for --compiler=swc --js
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants