简体   繁体   中英

nx EINVALIDPACKAGENAME when using npm

I have an nx monorepo it was working fine until recently, and now whenever I use npm install I get this error:

npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name "@package-name" of package "@package-name@file:/Users/usename/Documents/Workspace/my-projects/monorepo-name/packages/package-name": name can only contain URL-friendly characters.

I tried to delete package-lock.json , didn't work. I checked in my commit history if there was any change to package.json but there was none, and both solutions didn't work.

I successfully used npm install on my raspberry pi by changing my npm version to v6.14. But then I noticed the error was also present on my MAC with npm v9.2.

nx.json:

{
  "extends": "nx/presets/npm.json",
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": [
          "build",
          "lint",
          "test",
          "e2e"
        ]
      }
    }
  },
  "targetDefaults": {
    "lint": {
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json"
      ]
    },
    "test": {
      "inputs": [
        "default",
        "^default",
        "{workspaceRoot}/jest.preset.js"
      ]
    }
  },
  "defaultProject": "ntffi-lending"
}

package.json

{
  "name": "nx-test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "devDependencies": {
    "@nrwl/eslint-plugin-nx": "15.3.3",
    "@nrwl/jest": "15.3.3",
    "@nrwl/js": "15.3.3",
    "@nrwl/linter": "15.3.3",
    "@nrwl/node": "15.3.3",
    "@types/fs-extra": "^9.0.13",
    "@types/jest": "28.1.1",
    "@types/mocha": "^10.0.1",
    "@types/node": "18.7.1",
    "@types/ws": "^8.5.3",
    "@typescript-eslint/eslint-plugin": "^5.36.1",
    "@typescript-eslint/parser": "^5.36.1",
    "dotenv": "^16.0.3",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "jest": "28.1.1",
    "jest-environment-jsdom": "28.1.1",
    "nx": "15.3.3",
    "ts-jest": "28.0.5",
    "ts-node": "10.9.1",
    "typescript": "^4.9.4"
  },
  "workspaces": [
    "packages/*"
  ],
  "dependencies": {
    "@nftfi/js": "git+ssh://git@github.com:NFTfi-Genesis/nftfi.js.git",
    "bnc-sdk": "^4.6.3",
    "ethers": "^5.7.2",
    "fs-extra": "^11.1.0",
    "node-fetch": "^2.6.7",
    "tslib": "^2.3.0"
  }
}

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "Node",
    "importHelpers": true,
    "target": "ES2020",
    "module": "CommonJS",
    "lib": [
      "es2020"
    ],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@abis": [
        "packages/abis/src/index.ts"
      ],
      "@fs-helper": [
        "packages/fs-helper/src/index.ts"
      ],
      "@nftfi-helper": [
        "packages/nftfi-helper/src/index.ts"
      ],
      "@packages/*": [
        "packages/*/src"
      ],
      "@utils": [
        "packages/utils/src/index.ts"
      ],
      "@wrapper": [
        "packages/wrapper/src/index.ts"
      ],
      "@arcade-helper": [
        "packages/arcade-helper/src/index.ts"
      ]
    }
  },
  "include": [
    "./packages",
    "./apps"
  ],
  "exclude": [
    "node_modules",
    "tmp"
  ]
}

npm debug log

0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using npm@9.2.0
2 info using node@v16.15.1
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/Users/username/Documents/Workspace/my-projects/monorepo-name/.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:/Users/username/.npmrc Completed in 2ms
12 timing config:load:user Completed in 2ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 8ms
17 timing npm:load:configload Completed in 8ms
18 timing npm:load:mkdirpcache Completed in 0ms
19 timing npm:load:mkdirplogs Completed in 0ms
20 verbose title npm i
21 verbose argv "i"
22 timing npm:load:setTitle Completed in 16ms
23 timing config:load:flatten Completed in 2ms
24 timing npm:load:display Completed in 3ms
25 verbose logfile logs-max:10 dir:/Users/username/.npm/_logs/2022-12-29T19_56_31_220Z-
26 verbose logfile /Users/username/.npm/_logs/2022-12-29T19_56_31_220Z-debug-0.log
27 timing npm:load:logFile Completed in 5ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 34ms
31 silly logfile start cleaning logs, removing 1 files
32 timing config:load:flatten Completed in 0ms
33 timing arborist:ctor Completed in 0ms
34 silly logfile done cleaning log files
35 timing idealTree:init Completed in 673ms
36 timing idealTree:userRequests Completed in 0ms
37 silly idealTree buildDeps
38 timing idealTree Completed in 675ms
39 timing command:i Completed in 679ms
40 verbose stack Error: Invalid package name "@package-name" of package "@package-name@file:/Users/username/Documents/Workspace/my-projects/monorepo-name/packages/package-name": name can only contain URL-friendly characters.
40 verbose stack     at invalidPackageName (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:111:15)
40 verbose stack     at Result.setName (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:158:11)
40 verbose stack     at new Result (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:147:10)
40 verbose stack     at Function.resolve (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:59:15)
40 verbose stack     at Arborist.[nodeFromEdge] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1057:22)
40 verbose stack     at Arborist.[buildDepStep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:928:36)
40 verbose stack     at Arborist.[buildDeps] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:775:31)
40 verbose stack     at Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:206:29)
40 verbose stack     at async Promise.all (index 1)
40 verbose stack     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:156:5)
41 verbose cwd /Users/username/Documents/Workspace/my-projects/monorepo-name
42 verbose Darwin 22.1.0
43 verbose node v16.15.1
44 verbose npm  v9.2.0
45 error code EINVALIDPACKAGENAME
46 error Invalid package name "@package-name" of package "@package-name@file:/Users/username/Documents/Workspace/my-projects/monorepo-name/packages/package-name": name can only contain URL-friendly characters.
47 verbose exit 1
48 timing npm Completed in 736ms
49 verbose unfinished npm timer reify 1672343791274
50 verbose unfinished npm timer reify:loadTrees 1672343791275
51 verbose unfinished npm timer idealTree:buildDeps 1672343791948
52 verbose unfinished npm timer idealTree:#root 1672343791949
53 verbose code 1
54 error A complete log of this run can be found in:
54 error     /Users/username/.npm/_logs/2022-12-29T19_56_31_220Z-debug-0.log

Do I have to stay at node v6.14 forever? How could I solve this for npm 9 and above? Knowing that this was working fine yesterday

Manually go to the folder where the folder the package you want to update is located. Assuming based on your question it's file:/Users/usename/Documents/Workspace/my-projects/monorepo-name/packages From there, there run `npm install package-name. There's no need for the "@".

As far at the issue goes, it's not directly clear what you're running, because @package-name is not located anywhere other than in your debug log. If you're attempting to to pass in @package-name as a variable name to install packages, it seems that's not working how you're expecting.

This: @package-name@file:/Users/username/Documents/Workspace/my-projects/monorepo-name/packages/package-name should look like this: file:/Users/username/Documents/Workspace/my-projects/monorepo-name/packages/package-name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM