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

[BUG] Resolve dynamic imports #3038

Open
jaschaio opened this issue Mar 29, 2021 · 7 comments
Open

[BUG] Resolve dynamic imports #3038

jaschaio opened this issue Mar 29, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@jaschaio
Copy link
Contributor

Bug Report Quick Checklist

  • snowpack: 3.1.2
  • npm: 6.14.11
  • OS: macOS Catalina 10.15.7
  • node: 14.14.0

Describe the bug

Snowpack doesn't resolve dynamic imports:

import { library, icon } from '@fortawesome/fontawesome-svg-core';

const getIcon = async ( { icon: iconToFetch } ) => {

    const { [ iconToFetch ]: importedIcon } = await import( `@fortawesome/free-brands-svg-icons/${ iconToFetch }.js` );

    library.add( importedIcon );

    return icon( importedIcon, { classes } ).html

}

( async () => {

    const html = await getIcon( { icon: 'faFacebook' } );

    document.body.innerHTML = html;

} )();

Throws Uncaught (in promise) TypeError: Failed to resolve module specifier '@fortawesome/free-brands-svg-icons/faFacebook.js'

To Reproduce

Reproducible example: https://gist.github.com/jaschaio/321e794e7f8fb15d4bf9dfa0da46656c

Expected behavior

I would expect snowpack to notice the dynamic import, and replace the module identifier with the build output directory.

@amankkg
Copy link
Contributor

amankkg commented Apr 2, 2021

This is more likely to be related to esbuild rather than snowpack. Here is some discussion going on evanw/esbuild#700

TL;DR dynamic imports isn't something esbuild gonna support out of the box

@drwpow
Copy link
Collaborator

drwpow commented Apr 16, 2021

This does seem to be a bug; thanks for filing! Will investigate.

@drwpow drwpow added the bug Something isn't working label Apr 16, 2021
@drwpow drwpow self-assigned this Apr 16, 2021
@PeterPanZH
Copy link
Contributor

It seems that snowpack won't resolve the path when dynamic import has a variable in it.
Any update?

@IanVS
Copy link
Contributor

IanVS commented Jun 1, 2021

This seems related to #2861, right?

@PeterPanZH
Copy link
Contributor

This seems related to #2861, right?

Ah, right! This feature will solve the problem.

@IanVS
Copy link
Contributor

IanVS commented Jun 1, 2021

@drwpow I think this can be closed as a duplicate.

@aneta-kjeldsen
Copy link

I'm expiriencing exactly the same thing. Any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants