-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
SWC may generate invalid source map when inputSourceMap is provided #8789
Comments
@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
|
Seeing the same when updating from
|
My hunch is that this issue is caused by npm packages that include references to source maps (via One example is |
@davidmurdoch #8951 should fix your issue, although I'm not sure if it fixes this issue |
**Description:** Some libraries generate source maps but do not upload them to npm, which causes SWC to fail. **Related issue:** - #8789 (comment)
Sorry, I can't provide a smaller reproducible example yet, I don't know what boundary conditions are triggered. |
As an FYI - All of the errors we were seeing as a result of missing sourcemaps are not appearing. The sourcemaps are still not there, but we are at least not seeing those specific errors. Thank you @kdy1! |
I'm working on this, and the failure happens at Lines 423 to 425 in 54ac992
|
I added the babel transform process for comparison. From the results, it seems that babel's transform is always normal. Using swc transform babelResult, I got a new error: [Error: data did not match any variant of untagged enum InputSourceMap at line 1 column 2320758] {
code: 'InvalidArg'
} Babel transforms babelResult again and it passes |
It does not mean that the input source map is valid. |
ok, but invalid inputSourceMap is generated from first transform of swc. 😅 I'll see if there are smaller examples later. |
My guess is that
|
|
if id == 192 {
dbg!(src);
}
|
I left getsentry/rust-sourcemap#89 |
Something in v1.4.12 (and still present in v7.22.8) of @swc-project/swc is causing the following error when targeting es5 + sourcemap: true
In my case, I'm using
After looking at this a bit more, a minimal reproduction looks like this npm init
npm install @swc/[email protected] [email protected] [email protected] --save-dev
# create a file to build
echo "export default () => console.log('hello world');" > index.ts
# remove dist and tsup it
rm -rf ./dist/ && npx tsup --sourcemap --treeshake --target es5 ./index.ts
# results in error
# > ERROR failed to read input source map: failed to parse inline source map url It looks like there's a race condition. If you run again and |
getsentry/rust-sourcemap#91 is still not merged/published so it's expected |
Wait?, I tested version
console.log('==== use swc transform es6 to es5 ====');
// transformed successfully
const result = await transform(fileCode, {
filename: 'a.js',
sourceMaps: true,
inputSourceMap: fileMap,
jsc: { target: 'es5' },
minify: true,
module: { type: 'commonjs', strictMode: false },
});
fs.writeFileSync('./a.swc.js', result.code);
fs.writeFileSync('./a.swc.js.map', result.map);
const fs = require('fs');
const path = require('path');
const { SourceMapConsumer } = require('source-map'); // 0.7.4
async function verifySourcemap({ file, map, offset, line }) {
const sourceMap = fs.readFileSync(map, 'utf8');
const consumer = await new SourceMapConsumer(sourceMap);
const originalPosition = consumer.originalPositionFor({
line: line,
column: offset,
});
if (originalPosition.source === null) {
// @swc/core@nightly always return null for source
return null;
}
let miniCode = fs.readFileSync(file, 'utf8');
miniCode = miniCode.split('\n')[line - 1];
miniCode = miniCode.substring(offset - 20, offset + 20);
const source = consumer.sourceContentFor(originalPosition.source);
const code = source.split('\n')[originalPosition.line - 1];
// 1.7.6 that works
return { sourceFile: originalPosition.source, code, miniCode };
}
verifySourcemap({
file: path.join(__dirname, 'a.swc.js'),
map: path.join(__dirname, 'a.swc.js.map'),
line: 1,
offset: 207274,
}).then((result) => {
console.log('swc:', result);
}); Is this a new problem? |
Yes, please file another issue |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
https://stackblitz.com/~/github.com/noyobo/swc-issues
Input code
No response
Config
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
The text was updated successfully, but these errors were encountered: