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

Import in service-worker.ts from $lib throws #2321

Closed
frederikhors opened this issue Aug 29, 2021 · 2 comments · Fixed by #2326
Closed

Import in service-worker.ts from $lib throws #2321

frederikhors opened this issue Aug 29, 2021 · 2 comments · Fixed by #2326

Comments

@frederikhors
Copy link
Contributor

frederikhors commented Aug 29, 2021

Describe the bug

If I import this:

import { myFunc } from "$lib/utils";

in service-worker.ts, it throws like this:

[vite]: Rollup failed to resolve import "$lib/utils" from "src\service-worker.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

Why?

System Info

System:
    OS: Windows 10 10.0.19043
  Binaries:
    Node: 14.17.5 - C:\Program Files\nodejs\node.EXE
    npm: 7.21.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @sveltejs/adapter-static: 1.0.0-next.17 => 1.0.0-next.17
    @sveltejs/kit: 1.0.0-next.159 => 1.0.0-next.159
    svelte: 3.42.4 => 3.42.4

Severity

serious, but I can work around it

@JeanJPNM
Copy link
Contributor

I found the issue:

Here are the aliases for the client bundle:

resolve: {
alias: {
$app: path.resolve(`${build_dir}/runtime/app`),
$lib: config.kit.files.lib
}
},

Here are the aliases for the server bundle:

resolve: {
alias: {
$app: path.resolve(`${build_dir}/runtime/app`),
$lib: config.kit.files.lib
}
},

And here are the aliases for the service worker:

resolve: {
alias: {
'$service-worker': path.resolve(`${build_dir}/runtime/service-worker`)
}
}

As you can see, the rollup config for the service worker bundle doesn't include the $lib alias like the other two, I don't know if this is an error or is there by design.

But I if it is a bug I will happily open a pr.

@JeanJPNM
Copy link
Contributor

Thinking about it, it is problably a bug.

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

Successfully merging a pull request may close this issue.

2 participants