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

gts monorepo does not work with npm ? #752

Closed
tonirvega opened this issue Jan 10, 2023 · 5 comments
Closed

gts monorepo does not work with npm ? #752

tonirvega opened this issue Jan 10, 2023 · 5 comments

Comments

@tonirvega
Copy link

tonirvega commented Jan 10, 2023

I have this monorepo structure:

. root
├── node_modules
├── package.json
├── package-lock.json
├── packages
│   └── example-package
├── README.md
└── release-please-config.json

Then in my root package.json

{
  "name": "name-of-the-package",
  "version": "0.1.0",
  "description": "A monorepo",
  "main": "index.js",
  "scripts": {
    "test": "npm run test --workspaces",
    "lint": "npm run lint --workspaces"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/xxxxx/xxxxxx.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/xxxxx/xxxxxx/issues"
  },
  "homepage": "https://github.com/xxxxx/xxxxxx#readme",
  "workspaces": [
    "packages/*"
  ]
}

example-package - package.json

{
  "name": "@xxxxxxxxx/xxxxxxxxxxxx",
  "version": "0.1.0",
  "description": "An example package",
  "main": "index.js",
  "repository": "git://github.com/xxxxxxxxx/xxxxxxxxxxxx",
  "scripts": {
    "test": "jest",
    "tsc": "tsc",
    "lint": "gts lint",
    "clean": "gts clean",
    "prebuild": "clean",
    "compile": "tsc --module commonjs",
    "fix": "gts fix",
    "prepare": "npm run compile",
    "pretest": "npm run compile",
    "posttest": "npm run lint",
    "xxxxx": "ts-node ./main.ts"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/xxxxxxxxx/xxxxxxxxxxxx/issues"
  },
  "homepage": "https://github.com/xxxxxxxxx/xxxxxxxxxxxx#readme",
  "dependencies": {
    "@octokit/rest": "^19.0.5",
    "@types/nunjucks": "^3.2.1",
    "command-line-args": "^5.2.1",
    "js-yaml": "^4.1.0",
    "nunjucks": "^3.2.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.7",
    "@babel/preset-env": "^7.20.2",
    "@babel/preset-typescript": "^7.18.6",
    "@types/js-yaml": "^4.0.5",
    "@types/node": "^14.11.2",
    "@typescript-eslint/eslint-plugin": "^5.47.1",
    "babel-jest": "^29.3.1",
    "gts": "^4.0.0",
    "jest": "^29.3.1",
    "ts-node": "^10.9.1",
    "typescript": "~4.7.0"
  }
}

Then I run the lint command:

> npm run lint                                                                                     (arn:aws:eks:eu-west-1:041728615317:cluster/k8s-prefapp-pro/default)

> [email protected] lint
> npm run lint --workspaces


> @xxxxxx/[email protected] lint
> gts lint

version: 18
node:internal/modules/cjs/loader:958
  throw err;
  ^

Error: Cannot find module '/home/my-pc/monorepo/packages/example-package/node_modules/eslint/bin/eslint'
    at Module._resolveFilename (node:internal/modules/cjs/loader:955:15)
    at Module._load (node:internal/modules/cjs/loader:803:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.9.0
npm ERR! Lifecycle script `lint` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: @xxxxxx/[email protected] 
npm ERR!   at location: /home/my-pc/monorepo/packages/example-package 

I don´t underestand why is looking in the concrete example-package instead of the root directory. The only way I found to make it works is copying the node_modules/eslint package into the example-package directory.

/monorepo/packages/example-package/eslintrc.json

{
  "extends": "./node_modules/gts/",
  "rules": {
    "@typescript-eslint/no-explicit-any": "off"
  }
}

Greetings, thanks in advance

@AndreasAugustin
Copy link

Hi @arvegadev 👋
Is this possible related to #718 ?

barbarah added a commit to colonial-heritage/dataset-browser that referenced this issue Apr 12, 2023
I noticed that gts fix and gts link wasn't working in the npm workspaces. This is related to the issues:

gts monorepo does not work with npm ? google/gts#752
gts does not work in a yarn workspaces monorepo google/gts#490
The last issue is with yarn but has more discussion. One solution was using nohoist. This is not a default option with npm. So I tried with the following package https://github.com/zgriesinger/noist. But this did not fix the errors. The last solution mentioned was only linting from the root level; this works.

I have also subscribed to the issue [feature] support npm workspaces. There may be a better solution in the future.
@aabmass
Copy link
Member

aabmass commented Jun 21, 2023

I believe this is the same error as seen in #490 and #654 should fix the Error: Cannot find module issue

@aabmass
Copy link
Member

aabmass commented Oct 4, 2023

With the the latest 5.1.0 release, which includes #654, gts is working pretty well with npm workspaces monorepo for me. You only need the single gts generated .eslintrc.json in your repo root. I did have to move my eslintignore into the .eslintrc.json ignorePatterns, or you can leave individual eslintignore files in the individual workspaces directories.

@tonirvega
Copy link
Author

With the the latest 5.1.0 release, which includes #654, gts is working pretty well with npm workspaces monorepo for me. You only need the single gts generated .eslintrc.json in your repo root. I did have to move my eslintignore into the .eslintrc.json ignorePatterns, or you can leave individual eslintignore files in the individual workspaces directories.

I will try it. Thanks in advance.

@danielbankhead
Copy link
Contributor

Should be fixed via:

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

5 participants