How to get Dynamic Imports working on Rollup.js

I am trying to rollup a icon library using vue

I have a folder full of .svg

I run a command to scan the folders with all the .svgs and convert them to

export default `svg`;

and change the file to iconName.js

In the .vue document i require the correct file using :

Promise.resolve(
        import(`./icons/${this.iconSet}/${this.icn}`)
          .then(v => {
            console.log('required', v)
            this.svg = v.default
          })
          .catch(e => {
            console.log('err', e)
            this.error = true
          })
      )

In development, the .vue icon component works.
In production as an npm package i get:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received 'B:\\icons\\node_modules\\\u0000commonjs-dynamic-register:\\icons\\brands\\500px.js\\package.json' 

-> 500px.js is the first file in the icon pack and not the one being required by the vue component.
-> No clue why package.json is being appended (the files are contained within the dist folder – hoping relative paths would work but no luck

The above statement seems to be rendered from rollup via:

require("\u0000commonjs-dynamic-register:B:/icons/dist/icons/brands/500px.js")

B:/icons/dist -> the computer’s path to the repo -> i believe i have to shorten it to:

require("\u0000commonjs-dynamic-register:/icons/brands/500px.js")

Which gives me the same error

I’m lost and have spent days looking into this
thanks

https://github.com/mjmnagy/rollup-error-Sept-01-2020

61 thoughts on “How to get Dynamic Imports working on Rollup.js”

  1. Hi, i believe that i noticed you visited my weblog so i came to go back the prefer?.I am attempting to
    find things to enhance my site!I suppose its ok to make
    use of some of your concepts!!

    Reply
  2. I got this web page from my pal who told me regarding this website and now this
    time I am visiting this web page and reading very informative posts at this place.

    Reply
  3. Hey! Quick question that’s totally off topic. Do you know how to make your site mobile friendly?
    My web site looks weird when viewing from my iphone 4.
    I’m trying to find a template or plugin that might be able to resolve this
    issue. If you have any suggestions, please share. Cheers!

    Reply
  4. I was curious if you ever considered changing the page layout
    of your blog? Its very well written; I love what youve got to
    say. But maybe you could a little more in the
    way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 pictures.
    Maybe you could space it out better?

    Reply
  5. I’m really inspired along with your writing talents and also with the layout in your weblog.
    Is that this a paid subject matter or did you customize it your self?
    Either way keep up the nice quality writing, it is rare to look a nice blog like this one nowadays..

    Reply

Leave a Comment