robincode
robincode

Reputation: 590

VSCode Typescript why suggest "Auto import from 'node:path'"

I have a strange problem, I want to use path.join with nodejs, when I input jo it suggest me to use Auto import from 'node:path', of course this node:path is wrong, I don't know what configuration affects this result.

![enter image description here

enter image description here

tsconfig.json

{
    "compilerOptions": {
        "module": "ESNext",
        "target": "ES2017",
        "strict": true,
        "lib": ["es2019"],
        "moduleResolution": "Node",
        "types": ["node"]
    },
    "include": ["src/**/*.ts"],
    "exclude": ["node_modules"]
}

package.json

{
    ......
    "engines": {
        "node": ">=14.0.0"
    },
    "engineStrict": true,
    "devDependencies": {
        "@rollup/plugin-commonjs": "^18.0.0",
        "@rollup/plugin-node-resolve": "^11.2.1",
        "@rollup/plugin-typescript": "^8.2.1",
        "@types/jest": "^26.0.22",
        "@types/node": "^14.14.37",
        "jest": "^26.6.3",
        "jest-coverage-badges": "^1.1.2",
        "prettier": "^2.2.1",
        "rollup": "^2.45.2",
        "ts-jest": "^26.5.4",
        "ts-node": "^9.1.1",
        "tslib": "^2.2.0",
        "typescript": "^4.2.4"
    }
}

Upvotes: 1

Views: 804

Answers (1)

Alex D
Alex D

Reputation: 692

The pull request that made this change was here. https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51107

They appear to be discussing reverting the change until a change can be made to the TypeScript compiler to allow packages to define multiple canonical names for an exported module: https://github.com/microsoft/TypeScript/issues/42764

This change went into @types/[email protected], so in order to fix this problem you'll need to re-install your @types/node and set the version to 14.14.26.

This results in the behavior you're expecting: enter image description here

Alternatively, if you need something provided in a later version of @types/node and can't revert to an earlier version, you can still access the other import by moving your cursor over the red underlined missing import and using Ctrl+. or Cmd+. if you're on a mac, and choosing the second option to import from path instead of node:path. You can also click the little yellow lightbulb above. enter image description here

Upvotes: 1

Related Questions