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

compile errors when typechecking svelte.config.js with moduleResolution set to nodenext #591

Closed
DetachHead opened this issue Apr 14, 2023 · 8 comments

Comments

@DetachHead
Copy link

Describe the bug
when typechecking svelte.config.js with moduleResolution set to nodenext, the following compile errors occur:

node_modules/svelte-preprocess/dist/types/index.d.ts:2:106 - error TS2307: Cannot find module 'svelte/types/compiler/preprocess' or its corresponding type declarations.

2 import type { Processed as SvelteProcessed, Preprocessor as SveltePreprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess';
                                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/svelte-preprocess/dist/types/index.d.ts:4:35 - error TS2307: Cannot find module 'svelte/types/compiler/preprocess' or its corresponding type declarations.

4 export { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
svelte.config.js:12:14 - error TS2349: This expression is not callable.
  Type 'typeof import("/home/projects/sveltejs-kit-template-default-b9wpnr/node_modules/svelte-preprocess/dist/index")' has no call signatures.

12  preprocess: preprocess()
                ~~~~~~~~~~

Logs
Please include browser console and server logs around the time this bug occurred.

To Reproduce

  1. go to https://stackblitz.com/edit/sveltejs-kit-template-default-b9wpnr?file=svelte.config.js
  2. wait for the dev npm script to finish
  3. check the output

Expected behavior
A clear and concise description of what you expected to happen.

Information about your project:

  • svelte-preprocess version: 5.0.3

Additional context

other related issues:

@DetachHead
Copy link
Author

DetachHead commented Sep 11, 2023

minimized comment, off topic

this also causes two even more severe issues:

compile errors when trying to import another svelte component

<script lang='ts'>
    import Foo from './Foo.svelte' // svelte file that exists
</script>

<Foo/>
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json


====================================
Loading svelte-check in workspace: c:\Users\user\Documents\my-app2
Getting Svelte diagnostics...

c:\Users\user\Documents\my-app2\src\routes\+page.svelte:5:1
Warn: 'Foo' is not defined (svelte)

<Foo/>

====================================
svelte-check found 0 errors and 1 warning in 1 file

also why is an undefined variable only a warning instead of an error?

runtime crash

attempting to run my app with moduleResolution set to NodeNext causes this error:

ReferenceError: exports is not defined
    at eval (C:/Users/user/Documents/my-app2/src/routes/+page.svelte:14:24)
    at Object.$$render (C:/Users/user/Documents/my-app2/node_modules/svelte/src/runtime/internal/ssr.js:174:16)
    at Object.default (C:/Users/user/Documents/my-app2/.svelte-kit/generated/root.svelte:74:138)
    at eval (C:/Users/user/Documents/my-app2/node_modules/@sveltejs/kit/src/runtime/components/layout.svelte:8:41)
    at Object.$$render (C:/Users/user/Documents/my-app2/node_modules/svelte/src/runtime/internal/ssr.js:174:16)
    at eval (C:/Users/user/Documents/my-app2/.svelte-kit/generated/root.svelte:63:129)
    at $$render (C:/Users/user/Documents/my-app2/node_modules/svelte/src/runtime/internal/ssr.js:174:16)
    at Object.render (C:/Users/user/Documents/my-app2/node_modules/svelte/src/runtime/internal/ssr.js:182:17)
    at Module.render_response (C:/Users/user/Documents/my-app2/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:185:29)
    at async Module.render_page (C:/Users/user/Documents/my-app2/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:295:10)

@dummdidumm
Copy link
Member

Could you provide a reproduction for this? This sounds a bit unrelated - moduleResolution shouldn't have impact on how things are resolved at runtime, unless Vite is doing something funky there.

@DetachHead
Copy link
Author

yeah i can't reproduce that anymore updating to typescript 5, must've been the same issue as #612

however the issue in the OP still occurs

@dummdidumm
Copy link
Member

Fixed as part of #640

@AlexAegis
Copy link

I'm still getting it

src/internal/configurations.js:12:14 - error TS2349: This expression is not callable.
  Type 'typeof import("/home/alex/git/@aa/js-tooling/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]/node_modules/svelte-preprocess/dist/index")' has no call signatures.

12  preprocess: sveltePreprocess(),
                ~~~~~~~~~~~~~~~~

When trying to import the default import.

import { default as sveltePreprocess } from 'svelte-preprocess';

/**
 * @type {import('./types.js').Config}
 */
export const libConfiguration = {
	preprocess: sveltePreprocess(),
};

I think this happened before 6.0.0 too but I was just importing it from inside the package

import { sveltePreprocess } from 'svelte-preprocess/dist/autoProcess.js';

But I can no longer do this (since the exports object was defined in this versions package.json)

src/internal/configurations.js:4:34 - error TS2307: Cannot find module 'svelte-preprocess/dist/autoProcess.js' or its corresponding type declarations.

4 import { sveltePreprocess } from 'svelte-preprocess/dist/autoProcess.js';
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Relevant TSConfig:

{
	"compilerOptions": {
		"moduleResolution": "NodeNext",
		"module": "NodeNext"
	}
}

It would be nice to just have this export also exported as a named export. Default exports are such a headache sometimes..

With "moduleResolution": "Bundler", it works as intended

For now I can just // @ts-ignore it

@dummdidumm
Copy link
Member

If you do import sveltePreprocess from 'svelte-preprocess' everything should work as intended.

@AlexAegis
Copy link

No, I tried that too, forgot to mention.
image

dummdidumm added a commit that referenced this issue Jun 14, 2024
This deprecates the default export in favor of the new named export `sveltePreprocess`. It's done to ensure a better interop between CJS and ESM without resorting to hacks in the future. It also enables people using `"module": "NodeNext"` in their `tsconfig.json` to import without type errors.
The sub exports were also adjusted so that the transpiled TS output doesn't include `__importDefault` wrappers, which makes Node's static analysis miss those named exports.

Related: #591
@dummdidumm
Copy link
Member

dummdidumm commented Jun 14, 2024

In 6.0.1 you can now do import { sveltePreprocess } from 'svelte-preprocess' which should work with NodeNext, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants