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

Project not respecting root package.json module type #23060

Open
4 tasks
Jesse1989pp opened this issue Apr 29, 2024 · 3 comments
Open
4 tasks

Project not respecting root package.json module type #23060

Jesse1989pp opened this issue Apr 29, 2024 · 3 comments

Comments

@Jesse1989pp
Copy link

Jesse1989pp commented Apr 29, 2024

Current Behavior

In my setup i am using nuxt with layers. All layer got a project.json, but are not part of my yarn workspaces. When moving the root package.json to a type: module my cypress test start failing on:
Your configFile is invalid

I've seen quite some fixes on tsConfig which don't work. When i add an empy package.json in every folder with the module type. Then he's able to resolve the configFile as expected.

Expected Behavior

I would expect all folder to inherit the module type from the root.

GitHub Repo

https://github.com/Jesse1989pp/nx-issue-example/commits/main/
yarn && yarn nx run-many -t e2e

Steps to Reproduce

https://github.com/Jesse1989pp/nx-issue-example/commits/main/

  1. Create a Nuxt project with a layer, the app can have a package.json, the layer shouldn't
  2. Add Nx with cypress plugin. Project.json and cypress.config.ts in both app and layer
  3. Move package.json towards type:module.
  4. Run yarn && yarn nx run-many -t e2e(Error should hit on the layer)
  5. Add a basic package.json to the layer with type:module (Config should be found now)

Nx Report

Node   : 20.11.1
OS     : darwin-arm64
yarn   : 1.22.22

nx (global)        : 18.0.2
nx                 : 18.3.0
@nx/js             : 18.3.0
@nx/linter         : 18.3.0
@nx/eslint         : 18.3.0
@nx/workspace      : 18.3.0
@nx/cypress        : 18.3.0
@nx/devkit         : 18.3.0
@nx/eslint-plugin  : 18.3.0
@nrwl/tao          : 18.3.0
@nx/vite           : 18.3.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/cypress/plugin
---------------------------------------
Community plugins:
nx-stylelint : 17.1.4

Failure Logs

Your configFile is invalid: ../libs/domains/product/cypress.config.ts

It threw an error when required, check the stack trace below:

Error: Cannot find module 'file://../cypress.config.ts'

Package Manager Version

yarn 1.22.22

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)
@jaysoo
Copy link
Member

jaysoo commented May 7, 2024

Hi @Jesse1989pp I'm not able to see any errors from the repro you linked. Can you provide concrete steps for how to clone the repo and see the config file errors?

As for type: module and .ts or .js files. It is not a TypeScript problem per se. Node will look for the closest package.json file (in this case the lib's package.json), and if the type is module, then all .ts and .js files are treated as ESM, otherwise they are CJS.

You can rename the file to cypress.config.mjs or cypress.config.cjs, which will force Node to treat the file as ESM or CJS respectively. Note that this is not TypeScript, so you will have to make sure you are using plain JS in this case.

Unless I'm missing anything else, I don't think it's a bug on the Nx side.

@Jesse1989pp
Copy link
Author

Jesse1989pp commented May 8, 2024

Hi @Jesse1989pp I'm not able to see any errors from the repro you linked. Can you provide concrete steps for how to clone the repo and see the config file errors?

As for type: module and .ts or .js files. It is not a TypeScript problem per se. Node will look for the closest package.json file (in this case the lib's package.json), and if the type is module, then all .ts and .js files are treated as ESM, otherwise they are CJS.

You can rename the file to cypress.config.mjs or cypress.config.cjs, which will force Node to treat the file as ESM or CJS respectively. Note that this is not TypeScript, so you will have to make sure you are using plain JS in this case.

Unless I'm missing anything else, I don't think it's a bug on the Nx side.

@jaysoo Thanks for checking! The tsconfig chunks got mentioned in another issue with that error line. I know i can change the extension to mjs or cjs This led to another questions and problem:

  • Why does it work when i add a package.json in the project dir? This doesn't align with the expected behavior of respecting the closest package.json
  • Although documention mentions supporting the extensions. nx cypress plugin doesn't seem to be capable of finding the configs for inferred tasks.

On the lack of errors, just to be sure. You did run the actual e2e tests? I forgot to add that step in the reproduction, only added it next to the github repo. Added the step now.

Copy link

This issue has been automatically marked as stale because more information has not been provided within 7 days.
It will be closed in 21 days if no information is provided.
If information has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added stale and removed stale labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants