question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pnpm monorepo made with create-nx-workspace cannot immediately lint

See original GitHub issue

Current Behavior

Cannot lint in a fresh monorepo without complaints about ‘dotenv’. If I install dotenv globally, then it complains about more and more packages that need to be installed.

To get it to work, I had to install the following with pnpm add -D

  • "dotenv": "^16.0.1",
  • "eslint": "^8.21.0",
  • "@nrwl/eslint-plugin-nx": "^14.5.2",
  • "@typescript-eslint/eslint-plugin": "^5.32.0",
  • "eslint-config-prettier": "^8.5.0",
  • "eslint-plugin-unicorn": "^43.0.2",

Upon inspection, it makes sense that I would need these installed in order to be able to lint, and I know pnpm doesn’t hoist by default (and I know why that is a benefit). Perhaps the issue is that when I use the create-nx-workspace and I add my first library, perhaps I expect that these should be automatically installed (when using pnpm) just as things like jest are installed the first time I create a library.

And if this is the wrong place to post this, I’m happy to create an issue elsewhere and close this one.

Expected Behavior

In a fresh pnpm monorepo, I should be able to create a library and lint said library without package errors.

Steps to Reproduce

pnpx create-nx-workspace && pnpm nx g library example && pnpm nx lint example

Failure Logs

$ pnpm nx lint example

 >  NX   Cannot find module 'dotenv'

   Require stack:
   - /home/troy/Code/work/didit/node_modules/.pnpm/@nrwl+nx-cloud@14.3.0/node_modules/@nrwl/nx-cloud/lib/utilities/environment.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/@nrwl+nx-cloud@14.3.0/node_modules/@nrwl/nx-cloud/lib/nx-cloud-tasks-runner.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/@nrwl+nx-cloud@14.3.0/node_modules/@nrwl/nx-cloud/index.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/nx@14.5.1/node_modules/nx/src/tasks-runner/run-command.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/nx@14.5.1/node_modules/nx/src/command-line/run-one.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/nx@14.5.1/node_modules/nx/src/command-line/nx-commands.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/nx@14.5.1/node_modules/nx/bin/init-local.js
   - /home/troy/Code/work/didit/node_modules/.pnpm/nx@14.5.1/node_modules/nx/bin/nx.js
   Pass --verbose to see the stacktrace.

Environment

$ pnpm nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.16.0
   OS   : linux x64
   pnpm : 7.8.0
   
   nx : 14.5.1
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : Not Found
   @nrwl/eslint-plugin-nx : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.5.1
   @nrwl/js : Not Found
   @nrwl/linter : Not Found
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : 14.3.0
   @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.5.1
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
meeroslavcommented, Sep 14, 2022

@troywweber7, sorry for the inconvenience.

I have reached out to our colleaguesthe from nx-cloud team and someone will pick it up soon. Please do not continue the thread on (this) closed issue, especially since you opened another dedicated one.

In the meantime, as @barbados-clemens mentioned you can switch back to hosting to until we roll out the fixed version.

1reaction
dmaretskyicommented, Aug 11, 2022

@meeroslav It’s not in peer dependencies either:

{
  "name": "@nrwl/nx-cloud",
  "version": "14.3.0",
  "description": "Nx Cloud plugin for Nx",
  "keywords": [
    "Monorepo",
    "Nx",
    "Nx Cloud"
  ],
  "main": "index.js",
  "types": "index.d.ts",
  "author": "Victor Savkin",
  "license": "CC-BY-ND-3.0",
  "bugs": {
    "url": "https://github.com/nrwl/nx/issues"
  },
  "homepage": "https://nx.app",
  "generators": "./generators.json",
  "bin": {
    "nx-cloud": "./bin/nx-cloud.js"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "node-machine-id": "^1.1.12",
    "tar": "6.1.11",
    "strip-json-comments": "^3.1.1",
    "chalk": "4.1.0"
  },
  "typings": "./index.d.ts"
}

The problem appeared after I disabled hoisting. Probably some other package was installing dotenv and thats why it worked with hoisting. Without hoisting the package only has access to what’s declared in it’s package.json.

Anyway, I don’t think its a good idea to rely hoisting for the package to work. The behaviour is different between package managers and could change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setup a Monorepo with PNPM workspaces and speed it up ...
In this article we're going to have a deep dive into setting up a new monorepo using PNPM workspaces that hosts a Remix...
Read more >
Angular: @nxext/ionic-angular application schematic broken ...
Describe the bug In a freshly created pnpm + Nx monorepo, the @nxext/ionic-angular:application schematic fails to run.
Read more >
Workspace | pnpm
Workspace. pnpm has built-in support for monorepositories (AKA multi-package repositories, multi-project repositories, or monolithic repositories).
Read more >
Managing a full-stack, multipackage monorepo using pnpm
Learn why pnpm performs better than npm and how the many special workspaces features make it ideal for managing a multi-package monorepo.
Read more >
Newest 'monorepo' Questions - Page 4 - Stack Overflow
I am trying to establish module boundaries on compile level in typescript/npm based monorepos but cannot find a way to achieve it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found