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

Consistent strictness #5226

Closed
UltraCakeBakery opened this issue Jun 19, 2022 · 2 comments
Closed

Consistent strictness #5226

UltraCakeBakery opened this issue Jun 19, 2022 · 2 comments

Comments

@UltraCakeBakery
Copy link

UltraCakeBakery commented Jun 19, 2022

Describe the problem

It appears that sveltekit isn't as strict during dev as during build.

See the silly mistake i made in the snippet below. When in pnpm dev, this endpoint magically works and there is no problem with me not declaring the variable first. However, when you pnpm build > pnpm preview, the same script will cause a runtime error.

export function get()
{
    test = 123
    
    return {
        status: 200,
        body: {
            test
        }
    }
}

Describe the proposed solution

Normalizing strictness. Both environments should throw an error.

Alternatives considered

Keep this as is since it indirectly serves as a good reminder to check the sloppiness of the code you've written so far.
Or maybe run the endpoints in strict mode like after build? Not sure if that is possible though.

Importance

would make my life easier

Additional Information

No response

@gtm-nayan
Copy link
Contributor

Wouldn't say it's a duplicate since the previous one was closed and we ought to do something about it.

I used to think that this was caused by strict mode not being present in dev mode, but now I remember modules should be strict by default right? Might be something weird going on there because of pre bundling otherwise the solution would be a lint rule I guess.

@UltraCakeBakery UltraCakeBakery changed the title Always force the declaration of variables before assignments in endpoints Consistent strictness Jun 27, 2022
@Rich-Harris
Copy link
Member

This is a Vite issue — closing in favour of vitejs/vite#9197

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