webhintio/hint

[Bug] compilerOptions/moduleResolution>"bundler" invalid - vitejs

ucod3 opened this issue · 1 comments

ucod3 commented

Hello,

Every time I start a new TS project with Vite, I am getting this error message from webhint ext:

'compilerOptions/moduleResolution' must be equal to one of the allowed values 'Classic, Node, Node16, NodeNext'. Value found '"bundler"'. Or 'compilerOptions/moduleResolution' must match pattern '^(([Nn]ode)|([Nn]ode16)|([Nn]ode[Nn]ext)|([Cc]lassic))$'. Value found 'bundler'Microsoft Edge Toolstypescript-config/is-valid

Understanding from TY Doc is that the "bundler" is a valid option:

Module Resolution - moduleResolution
Specify the module resolution strategy:

'node16' or 'nodenext' for modern versions of Node.js. Node.js v12 and later supports both ECMAScript imports and CommonJS require, which resolve using different algorithms. These moduleResolution values, when combined with the corresponding module values, picks the right algorithm for each resolution based on whether Node.js will see an import or require in the output JavaScript code.

'node10' (previously called 'node') for Node.js versions older than v10, which only support CommonJS require. You probably won’t need to use node10 in modern code.

'bundler' for use with bundlers. Like node16 and nodenext, this mode supports package.json "imports" and "exports", but unlike the Node.js resolution modes, bundler never requires file extensions on relative paths in imports.

bundler does not support resolution of require calls. In TypeScript files, this means the import mod = require("foo") syntax is forbidden; in JavaScript files, require calls are not errors but only ever return the type any (or whatever an ambient declaration of a global require function is declared to return).

'classic' was used in TypeScript before the release of 1.6. classic should not be used.

There is a handbook reference page on Module Resolution

https://www.typescriptlang.org/tsconfig#moduleResolution

tsconfig.json generated by Vite:

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"]
}

Thanks for looking into this!

ucod3 commented

Duplicate:
#5719