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

Svelte 5 error "Cannot access '_' before initialization" in version 241 #13081

Closed
98mux opened this issue Aug 30, 2024 · 4 comments · Fixed by #13082
Closed

Svelte 5 error "Cannot access '_' before initialization" in version 241 #13081

98mux opened this issue Aug 30, 2024 · 4 comments · Fixed by #13082
Labels
Milestone

Comments

@98mux
Copy link
Contributor

98mux commented Aug 30, 2024

Describe the bug

A bug that appears in next.241 for me.

Reproduction

I was unable to replicate it on the repl

This code:

<script lang="ts" context="module">
	import _ from 'lodash';
	export const b = _.cloneDeep({ f: '' });
</script>

Causes the error "ReferenceError: Cannot access '_' before initialization"

In my project - for any library, not just lodash.

It only happens in svelte 5 version 241
Svelte 5 version 240 and earlier does not have this issue.

It only happens with npm run dev
npm run build works fine

Logs

ReferenceError: Cannot access '_' before initialization

System Info

System:
    OS: macOS 13.5
    CPU: (8) arm64 Apple M1
    Memory: 93.67 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.0 - /usr/local/bin/node
    npm: 10.5.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 128.0.6613.86
    Safari: 16.6
  npmPackages:
    svelte: 5.0.0-next.241 => 5.0.0-next.241

Severity

blocking an upgrade

@98mux 98mux changed the title Svelte 5 regression (appears in next.241 and not next.240) Svelte 5 error Cannot access '_' before initialization in version 421 Aug 30, 2024
@98mux 98mux changed the title Svelte 5 error Cannot access '_' before initialization in version 421 Svelte 5 error "Cannot access '_' before initialization" in version 421 Aug 30, 2024
@98mux 98mux changed the title Svelte 5 error "Cannot access '_' before initialization" in version 421 Svelte 5 error "Cannot access '_' before initialization" in version 241 Aug 30, 2024
@Conduitry Conduitry added the bug label Aug 30, 2024
@Conduitry Conduitry added this to the 5.0 milestone Aug 30, 2024
@Conduitry
Copy link
Member

This actually is reproducible on the REPL, in that the client-side compiled JS for the above component is:

export const b = _.cloneDeep({ f: '' });

import * as $ from "svelte/internal/client";
import _ from 'lodash';

export default function App($$anchor, $$props) {
	$.push($$props, false);
	$.init();
	$.pop();
}

Interestingly, the server-side compiled version is fine.

@dummdidumm
Copy link
Member

cc @benmccann, likely a result of #13048

@benmccann
Copy link
Member

oof. yeah, that's no good. thanks for letting me know. I'd be happy to take a look at it, but it looks like @paoloricciuti beat me to it. Thanks @paoloricciuti!

@paoloricciuti
Copy link
Member

oof. yeah, that's no good. thanks for letting me know. I'd be happy to take a look at it, but it looks like @paoloricciuti beat me to it. Thanks @paoloricciuti!

No problem at all... I'm not 100% confident with the elegance of my solution but it works

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

Successfully merging a pull request may close this issue.

5 participants