Skip to content

why not pass the transform sourcemap to webpack  #154

Closed as not planned
Closed as not planned

Description

@luhc228

Hi~ I'm now using unplugin to write a plugin and the plugin will be transformed to webpack plugin and esbuild plugin.

I only use one plugin to transform the .jsx file. In other words, there is only one loader to handle .jsx file. So the transform function's param, map is undefined. But after I transform the .jsx file, I get the res.map value which is not the undefined. I am confused why the unplugin use the map first but not the res.map?

callback(null, res.code, map == null ? map : (res.map || map))

Here is how I use the unplugin transform hook:
https://github.com/ice-lab/ice-next/blob/f5755a0c0afdda87b97393ce6dc44f0ac9b4db84/packages/webpack-config/src/unPlugins/compilation.ts#L104

webpack loader load order: https://webpack.js.org/contribute/writing-a-loader/#complex-usage

Activity

  1. antfu commented on Aug 15, 2022

    @antfu
    Member

    If there was no map from the beginning and we provide a map, it will cause Webpack to throw an error on merging the sourcemap with null

  2. luhc228 commented on Aug 15, 2022

    @luhc228
    Author

    I make a change like these in node_modules/unplugin/dist/webpack/transform.js, it works. So will the unplugin makes a change? @antfu

    - callback(null, res.code, map == null ? map : (res.map || map)) 
    + callback(null, res.code, res.map || map)
  3. antfu commented on Aug 29, 2022

    @antfu
    Member

    I would need a reproduction to confirm this is a valid fix.

  4. luhc228 commented on Aug 30, 2022

    @luhc228
    Author

    @antfu Thank you for your replying.

    Here is my demo which can reproduct the problem.

    You can install the dependencies and the run the script npm start to start the dev server.

    Well, u can see this line. I console the transform result and the sourcemap is correct.

    But the final sourcemap is incorrect.

    image

  5. antfu commented on Oct 26, 2026

    @antfu
    Member

    This is a duplicate of #616. That issue has a fix in #615, so please follow it there. Tell us if yours is different and we will reopen.

    🤖 Automated by an agent.

  6. added
    duplicateThis issue or pull request already exists
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions