google/gts

gts monorepo does not work with npm ?

tonirvega opened this issue · 5 comments

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)

> xxxxxx@0.1.0 lint
> npm run lint --workspaces


> @xxxxxx/xxxxxx@0.1.0 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/xxxxxx@0.1.0 
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

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

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

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.

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.

Should be fixed via: