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

transform providing an inputSourceMap throws an error [bad reference to source #299] #8789

Open
noyobo opened this issue Mar 28, 2024 · 1 comment · Fixed by #8800
Open
Assignees
Labels
Milestone

Comments

@noyobo
Copy link

noyobo commented Mar 28, 2024

Describe the bug

https://stackblitz.com/~/github.com/noyobo/swc-issues

$ npm run build 

[Error: failed to read input source map from user-provided sourcemap

Caused by:
    bad reference to source #299] {
  code: 'GenericFailure'
}

Input code

No response

Config

import {transform} from '@swc/core';
import fs from "node:fs";

const fileCode = fs.readFileSync("./a.js", "utf-8");
const fileMap = fs.readFileSync("./a.js.map", "utf-8");
// valid check https://evanw.github.io/source-map-visualization/


// transformed successfully
const result = await transform(fileCode, {
  filename: 'a.js',
  sourceMaps: true,
  inputSourceMap: fileMap,
  jsc: {target: 'es5'},
  module: {type: "commonjs", strictMode: false},
})

// fs.writeFileSync("./a.transformed.js", result.code);
// fs.writeFileSync("./a.transformed.js.map", result.map);

// Using the result again to transform throws an error
// and verification failed in https://evanw.github.io/source-map-visualization/
await transform(result.code, {
  filename: "a.js",
  // minify: true,
  sourceMaps: true,
  inputSourceMap: result.map,
  // jsc: {
  //   target: "es5",
  //   minify: {
  //     compress: {
  //       inline: 0,
  //       drop_debugger: false,
  //       passes: 1,
  //     },
  //     mangle: {
  //       toplevel: false,
  //       keep_classnames: false,
  //       keep_fnames: false,
  //       keep_private_props: false,
  //       ie8: false,
  //       safari10: false,
  //     },
  //     format: {
  //       asciiOnly: true,
  //       wrapIife: true,
  //     },
  //   },
  // },
  module: {type: "commonjs", strictMode: false},
}).catch((e) => {
  /**
   * [Error: failed to read input source map from user-provided sourcemap
   *
   * Caused by:
   *     bad reference to source #299] {
   *   code: 'GenericFailure'
   * }
   */
  console.log(e);
});

Playground link (or link to the minimal reproduction)

https://stackblitz.com/~/github.com/noyobo/swc-issues

SWC Info output

No response

Expected behavior

The transformed sourceMap content can be used again

Actual behavior

No response

Version

1.4.11

Additional context

No response

@noyobo noyobo added the C-bug label Mar 28, 2024
@noyobo noyobo changed the title tansform providing an inputSourceMap throws an error [bad reference to source #299] transform providing an inputSourceMap throws an error [bad reference to source #299] Mar 28, 2024
@kdy1 kdy1 added this to the Planned milestone Mar 29, 2024
@kdy1 kdy1 self-assigned this Apr 2, 2024
@kdy1 kdy1 closed this as completed in #8800 Apr 3, 2024
kdy1 added a commit that referenced this issue Apr 3, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.12 Apr 4, 2024
@noyobo
Copy link
Author

noyobo commented Apr 9, 2024

@kdy1 Is it fixed in v1.4.12? I tried to use 1.4.12 and the problem still exists.

https://stackblitz.com/~/github.com/noyobo/swc-issues

> npx -y swc-info@latest && node ./transform-a.mjs


    Operating System:
        Platform: linux
        Arch: x64
        Machine Type: undefined
        Version: Ubuntu 20.04.0 LTS Tue Apr 09 2024 10:36:06 GMT+0800 (中国标准时间)
        CPU: (3 cores)
            Models: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz

    Binaries:
        Node: 18.18.0
        npm: 10.2.3
        Yarn: 1.22.19
        pnpm: 8.15.3

    Relevant Packages:
        @swc/core: 1.4.12
        @swc/helpers: N/A
        @swc/types: N/A
        

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A

failed to process js file

Caused by:
    0: failed to read input source map from user-provided sourcemap
    1: bad reference to source #299

@kdy1 kdy1 reopened this Apr 9, 2024
@kdy1 kdy1 modified the milestones: v1.4.12, Planned Apr 9, 2024
@kdy1 kdy1 removed their assignment Apr 9, 2024
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants