modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.2k stars 278 forks source link

dev-server-esbuild does not work with "moduleResolution": "node16" #2173

Open arv opened 1 year ago

arv commented 1 year ago

It looks like @web/dev-server-esbuild does not work when the moduleResolution is set to node16 in tsconfig.json

Here is a sample repo:

https://github.com/arv/test-web-dev-server-tsconfig-module-resolution-node16

And here is the output again:

$ npx tsc --noEmit
node_modules/@web/dev-server/index.d.mts:2:15 - error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './dist/index.js'?

2 export * from './dist/index';
                ~~~~~~~~~~~~~~

src/test.ts:2:35 - error TS7016: Could not find a declaration file for module '@web/dev-server-esbuild'. '/Users/arv/src/test-web-dev-server-tsconfig-module-resolution-node16/node_modules/@web/dev-server-esbuild/index.mjs' implicitly has an 'any' type.
  There are types at '/Users/arv/src/test-web-dev-server-tsconfig-module-resolution-node16/node_modules/@web/dev-server-esbuild/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@web/dev-server-esbuild' library may need to update its package.json or typings.

2 import * as devServerEsbuild from '@web/dev-server-esbuild';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~

Found 2 errors in 2 files.

Errors  Files
     1  node_modules/@web/dev-server/index.d.mts:2
     1  src/test.ts:2

It seems to me like the thing that needs to happen is to start using file extensions on the imports.

One way to ensure this is working is to start using moduleResolution node16 in this repo.

koddsson commented 1 year ago

Hey @arv! I think we need to update TypeScript before we can set moduleResolution: 'node16'. I'm not sure what release it was introduced in, but I'm getting an error when I'm trying to change the setting right now. We probably need to wait for #2032 to land first.