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

Failed to resolve module specifier while importing external dependency through script with type=module #399

Closed
bhvngt opened this issue Jul 21, 2022 · 1 comment
Labels
bug Something isn't working triage Awaiting triage by a project member

Comments

@bhvngt
Copy link

bhvngt commented Jul 21, 2022

Describe the bug

I would like preload one of my external dependency. For this I have placed a script tag with type="module" as follows

<html lang="en">
	<head>
		<script type="module">
			import '@master/css';
		</script>

This snippet works with vite when I remove svelte-kit plugin. However, it throws following error on the browser console when I use this plugin.

Uncaught TypeError: Failed to resolve module specifier "@master/css". Relative references must start with either "/", "./", or "../".

This happens on both development as well as production build. As a workaround I am copying the @master/css/index.js to my static folder and importing it as import "/master.css.js"

Reproduction

Here's the reproduction.

working.html and working.vite.config.js has the config that works when sveltekit() plugin is removed.

You will need to append src/working.html to the url since the entry point has changed.

Logs

Uncaught TypeError: Failed to resolve module specifier "@master/css". Relative references must start with either "/", "./", or "../".

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    vite: ^3.0.1 => 3.0.2

Severity

annoyance

@bhvngt bhvngt added bug Something isn't working triage Awaiting triage by a project member labels Jul 21, 2022
@bluwy
Copy link
Member

bluwy commented Jul 21, 2022

This is because SvelteKit controls serving the HTML, which doesn't call transformIndexHtml, a hook that applies Vite's transformation such as your example. But in the bigger picture, perhaps you're looking for sveltejs/kit#3127? Closing as this isn't an issue in vite-plugin-svelte.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Awaiting triage by a project member
Projects
None yet
Development

No branches or pull requests

2 participants