question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`resolveId` doesn’t seem to work in webpack

See original GitHub issue

I use resolveId and load to implement the plugin logic:

export default createUnplugin(() => ({
  name: 'unplugin-starter',
  resolveId(id) {
    return id === 'my-unplugin-virtual-id' ? id : null
  },
  load(id) {
    if (id === 'my-unplugin-virtual-id')
      return 'export default \'hello my-unplugin\''
  },
}))

When I used this plugin in webpack, it reported an error. But it’s ok in vite.

import str from 'my-unplugin-virtual-id'
Module not found: Error: Can't resolve 'my-unplugin-virtual-id' in 'D:\Projects\my-unplugin\playground\webpack\src'

This is my minimal demo that can reproduce the problem:https://github.com/Codpoe/unplugin-minimal-demo. And I had this problem on Windows, I haven’t tested it on Mac…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, Oct 21, 2022

I’m getting this as well. In case it’s helpful, here are three reproductions:

0reactions
Codpoecommented, Sep 18, 2021

I tried to do what you said, but it still didn’t work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack Externals doesn't seem to work for React
I'm creating a React Library, already published it to npm somehow. But, I faced several issues/questions during the development flow.
Read more >
rollup.js
js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the...
Read more >
Hooking into import with Webpack & Rollup - AnDrew
resolveId is called for every module being imported, this is run recursively through all files until no further imports are found. The function ......
Read more >
unplugin - npm
Hook, Rollup, Vite, Webpack 4, Webpack 5, esbuild ... It doesn't pass any arguments. ... Other hooks like load or resolveId work fine....
Read more >
Writing build plugins - YouTube
It's common to use a build tool as part of development, ... In this session, we develop the same plugin for both Rollup...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found