rxdi / firelink

Firebase. gcloud and monorepos are not combining very well until they met @rxdi/firelink
MIT License
68 stars 9 forks source link

Error: EISDIR: illegal operation on a directory, read #50

Open MA-Jesse opened 2 years ago

MA-Jesse commented 2 years ago

We're using a mono-repo with yarn workspaces and lerna. We have no-hoist enabled for packages/functions so all node_modules related to packages/functions are contained there.

When running firelink from to packages/functions we get this error....

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[Error: EISDIR: illegal operation on a directory, read] {
  errno: -4068,
  code: 'EISDIR',
  syscall: 'read'
}

Not sure why but running firelink from the root directory of the repo doesn't throw this error.

R-Iqbal commented 2 years ago

So from some further investigation, it appears to be caused by one of our fireDependencies

  "fireDependencies": {
    "@claimsgate/core": "../core",
    "@claimsgate/core-types": "../core-types"
  },

Removing @claimsgate/core from our fireDependencies prevents the issue from happening. But looking further into it, there are almost no differences between the @claimsgate/core and @claimsgate/core-types folders.

R-Iqbal commented 2 years ago

Removing node_modules from @claimsgate/core appears to fix the issue but this is odd. The only dependencies for @claimsgate/core are "@claimsgate/core-types": "1.2.0".

In our fireConfig we also exclude the node_modules folder. Potentially, there is some permission issue when reading/writing to the node_modules in packages/core from packages/functions

R-Iqbal commented 2 years ago

To summarise:

  1. I'm not entirely sure why removing node_modules from @claimsgate/core causes Firelink to start working correctly.
  2. The only real change we have made to @claimsgate/core has been enabling eslint

@claimsgate/core package.json

{
  "name": "@claimsgate/core",
  "version": "1.2.0",
  "description": "",
  "scripts": {
    "compile": "npx tsc",
    "compile:watch": "npx tsc -w"
  },
  "keywords": [],
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "author": "",
  "dependencies": {
    "@claimsgate/core-types": "1.2.0",
    "@typescript-eslint/eslint-plugin": "^5.16.0",
    "@typescript-eslint/parser": "^5.16.0"
  },
  "devDependencies": {
    "eslint": "^8.11.0",
    "typescript": "^4.5.4"
  },
  "private": true
}

@claimsgate/core tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "declaration": true,
    "strict": false,
    "esModuleInterop": true,
    "allowJs": false,
    "baseUrl": "./src",
    "outDir": "dist",
    "target": "es2020",
    "composite": true,
    "types": ["@claimsgate/core-types"],
    "paths": {}
  },
  "references": [{ "path": "../core-types" }],
  "exclude": ["node_modules", "**/*.spec.ts", "./dist"],
  "include": ["src/**/*.ts"],
  "files": ["index.ts"]
}

@claimsgate/functions package.json


{
  "fireDependencies": {
    "@claimsgate/core-types": "../core-types",
    "@claimsgate/core": "../core"
  },
  "fireConfig": {
    "runner": "firebase",
    "outFolderName": ".packages",
    "outFolderLocation": ".",
    "excludes": [
      "node_modules"
    ]
  }
}
R-Iqbal commented 2 years ago

Okay I figured it out. Removing @claimsgate/core from no-hoist in our root package.json solved the problem!

I'm guessing there's an error in resolving the directory of node_modules somewhere in the code when dependencies are hoisted for a given fireDependency

Stradivario commented 2 years ago

Wow thanks for the great information provided i will try to replicate the issue and see what causes it

Is your project started with some Yarn or Lerna starter if it is possible to clone it directly and test the things out ?

Anyway i will try to mimic the problem using your provided information in this ticket for now.

Great job guys!