cypress: Plugins file fails on lodash import after upgrade to 7.1.0
Current behavior
When I upgrade my cypress instance from 6.8.0 to 7.1.0 I get an error where cypress thinks that my plugins file has invalid syntax, but the root cause is that it can’t import lodash that I use for deep merge of default & our settings.
This used to work fine & I’ve tried to mitigate this by creating a custom importer akin to this: https://stackoverflow.com/questions/62298396/making-a-dependencys-dependencies-available-with-yarn-2/64242991#64242991 …alas it didn’t help
I do have lodash installed in the root “workspace”.
**Message:** The plugins file is missing or invalid.
Your `pluginsFile` is set to `…/web-ui/cypress/plugins/index.ts`, but either the file is missing, it contains a syntax error, or threw an error when required. The `pluginsFile` must be a `.js`, `.ts`, or `.coffee` file.
Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.
Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
**Details:** Error: Cannot find module 'lodash'
Require stack:
- …/web-ui/cypress/plugins/index.ts
- /home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js
- /home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/child/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:887:15)
at Module._load (internal/modules/cjs/loader.js:732:27)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/opt/dev/…/pool/web-ui/cypress/plugins/index.ts:8:19)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at runPlugins (/home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js:175:15)
at Object.<anonymous> (/home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/child/index.js:8:25)
at Module._compile (internal/modules/cjs/loader.js:1078:30)
**Stack trace:**
Error: The plugins file is missing or invalid.
Your pluginsFile is set to …/web-ui/cypress/plugins/index.ts, but either the file is missing, it contains a syntax error, or threw an error when required. The pluginsFile must be a .js, .ts, or .coffee file.
Or you might have renamed the extension of your pluginsFile. If that’s the case, restart the test runner.
Please fix this, or set pluginsFile to false if a plugins file is not necessary for your project.
at Object.get (/home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/errors.js:988:15)
at EventEmitter.<anonymous> (/home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/index.js:154:21)
at EventEmitter.emit (events.js:315:20)
at ChildProcess.<anonymous> (/home/…/.cache/Cypress/7.1.0/Cypress/resources/app/packages/server/lib/plugins/util.js:19:22)
at ChildProcess.emit (events.js:315:20)
at emit (internal/child_process.js:903:12)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
### Test code to reproduce
I've tried to reproduce this in the `cypress-test-tiny`, but wasn't able to… if you can point me in some direction I'll provide what's needed
### Versions
- Operating System: Ubuntu 20.10
- Cypress: 7.1.0
- Yarn: 2.4.0-git.20210226.hash-97663a9d with P'n'P enabled & workspaces setup
- Typescript: 4.2.3
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 23 (13 by maintainers)
Tried dig into the code, this is an regression introduced by https://github.com/cypress-io/cypress/pull/15292
Yarn pnp rely on node_options env variable to work. Prior to 7.0.0, we restored the node_options in the process that build plugin files so yarn pnp is able to pick that up. The logic was removed in #15292 and therefore caused this issue.
@flotwig i saw you made the change, would that be possible to bring the node_options restore logic back (in the sub process that build plugin and tests) ? I think it make sense for plugin access what user set in their node_options
The code for this is done in cypress-io/cypress#17335, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.
6.9.1is OK,7.0.0has the reported problem plus it starts very slowly, and it reports some new issues to STDOUT