Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with "moduleResolution": "Node16" inside tsconfig.json #1965

Closed
ivanhofer opened this issue Mar 26, 2023 · 2 comments
Closed

issues with "moduleResolution": "Node16" inside tsconfig.json #1965

ivanhofer opened this issue Mar 26, 2023 · 2 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@ivanhofer
Copy link
Contributor

Describe the bug

When setting moduleResolution to Node16 inside tsconfig.json I encounter two issues:

  1. the "zero-effort typesafety" functionality stops working

  2. if I run svelte-check:watch and safe the tsconfig.json file, the process crashes with following error message

    Watching for file changes.../home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:139552
            return !!entry.sourceFile;
                           ^
    
    TypeError: Cannot read properties of undefined (reading 'sourceFile')
        at isDocumentRegistryEntry (/home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:139552:24)
        at getDocumentRegistryEntry (/home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:139612:25)
        at Object.releaseDocumentWithKey (/home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:139718:25)
        at /home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:169519:45
        at Object.forEach (/home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:181:30)
        at Object.dispose (/home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:169518:20)
        at dispose (/home/my-app/node_modules/.pnpm/[email protected][email protected]/node_modules/svelte-check/dist/src/index.js:90308:25)
        at watchConfigCallback (/home/my-app/node_modules/.pnpm/[email protected][email protected]/node_modules/svelte-check/dist/src/index.js:90343:9)
        at /home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:6724:17
        at /home/my-app/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:6439:180
    

Reproduction

demo repository: https://github.com/ivanhofer/svelte-check-moduleresolution-node16

  1. /routes/+page.svelte contains an error. If you run svelte-check nothing shows up. data is typed as any.
    Once moduleResolution removed from the tsconfig.json, the error shows up.
  2. run check:watch and hit save on the opened tsconfig.json file. The process should crash.
    Once moduleResolution removed from the tsconfig.json, saving that file does not crash the process.

Expected behaviour

I would expect the Svelte language-tools also to function with moduleResolution set to Node16

System Info

  • OS: WSL with Ubuntu 22.04 on Windows 11
  • IDE: VSCode

Which package is the issue about?

Svelte for VS Code extension, svelte-language-server, svelte-check

Additional Information, eg. Screenshots

No response

@ivanhofer ivanhofer added the bug Something isn't working label Mar 26, 2023
@ivanhofer
Copy link
Contributor Author

I assume replacing all import('./$types') with import('./$types.d.js') in https://github.com/sveltejs/language-tools/blob/master/packages/svelte2tsx/src/helpers/sveltekit.ts should solve issue nr 1 without affecting the current compatability.

@dummdidumm
Copy link
Member

dummdidumm commented Mar 27, 2023

The type issue is easily solvable through import('./$types.js').

The other issue is hard to solve. The problem is that we set impliedNodeFormat in module-loader.ts - but at that point the document registry has put the corresponding sourceFile into a bucket, using impliedNodeFormat as part of the key. Now that impliedNodeFormat changed from undefined to something the lookup while cleaning up due to the restart will fail, as the computed key is different. I'm not sure how we can reliably solve this. One idea is to only temporarily set impliedNodeFormat inside resolve in module-loader.ts, but that might have implications on other parts which are undesirable (one I know of is the error message of failed-to-resolve imports is not as good anymore). Another possibility is to provide our own document registry to createLanguageService where the patch the relevant methods to set impliedNodeFormat sooner, which also has drawbacks because it requires accessing multiple internal methods.

dummdidumm added a commit to dummdidumm/language-tools that referenced this issue Mar 27, 2023
dummdidumm added a commit that referenced this issue Mar 27, 2023
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants