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

[Bug]: commonjs source-maps sources point to .js and cjs files contain duplicated sourceMappingURL #27320

Closed
2 tasks done
Hotell opened this issue Mar 24, 2023 · 4 comments
Closed
2 tasks done
Labels

Comments

@Hotell
Copy link
Contributor

Hotell commented Mar 24, 2023

Library

React Components / v9 (@fluentui/react-components)

Are you reporting Accessibility issue?

None

Reproduction

Pre swc (using TS):

Post swc:

Bug Description

Actual Behavior

After migration to swc, source maps for commonjs inputs don't point to TS original source anymore.

Also the sourceMappingURL is being printed twice within cjs output (which is present within the source map )

Expected Behavior

This regression is actually expected, but we didn't thought about it while implementing the change, as our transpilation pipeline changed

From

graph LR;
 
S["Start"]
E["End"]
B["Babel"]

    S-->TSC:esm-->B
    S-->TSC:cjs-->B
    B-->E;
Loading

To

graph LR;
 
S["Start"]
E["End"]
B["Babel"]

    S-->SWC:esm-->B-->SWC:cjs-->E
Loading

Besides the duplicated sourceMappingURL emit within cjs output, it shouldn't have any real impact for consumers, as we use sourcesContent which is a source of truth for the actual source mapping.

More feedback is needed.

Actionable for now is to reduce that duplicate emit for commonjs.

Logs

No response

Requested priority

Normal

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Related issues/PRs

#27250

@Hotell Hotell changed the title [Bug]: commonjs source-maps point to esm js and contain duplicated sourceMappingURL [Bug]: commonjs source-maps point to esm js and cjs files contain duplicated sourceMappingURL Mar 24, 2023
@Hotell Hotell changed the title [Bug]: commonjs source-maps point to esm js and cjs files contain duplicated sourceMappingURL [Bug]: commonjs source-maps sources point to .js and cjs files contain duplicated sourceMappingURL Mar 24, 2023
@layershifter
Copy link
Member

It's clearly SWC bug: https://codesandbox.io/p/sandbox/funny-wildflower-wnxf1b

$ npx swc ./index.js -o output.esm.js --config module.type=es6 --source-maps=true

⬇️⬇️⬇️

import path from "path";
console.log("Hello CodeSandbox", path.dirname("./foo/bar.js"));


//# sourceMappingURL=output.esm.js.map
$ npx swc ./output.esm.js -o output.cjs.js --config module.type=commonjs --source-maps=true

⬇️⬇️⬇️

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
var _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
console.log("Hello CodeSandbox", _path.default.dirname("./foo/bar.js")); //# sourceMappingURL=output.esm.js.map


//# sourceMappingURL=output.cjs.js.map

👆"sourceMappingURL" comment is doubled

@Hotell
Copy link
Contributor Author

Hotell commented Mar 30, 2023

thanks for taking additional look on this @layershifter 🙌.

yeah I'm aware about this. not sure if it's a bug or rather missing feature.

Babel does this like following -> checks for that source map comment, removes it as present, generates new one to provide accurate source map to transformed content. Though some users reported this as bug on babel side.

SWC doesn't do what babel does, which might be missing feature ?

anyways lets report this to swc folks. ty

@microsoft-github-policy-service

Because this issue has not had activity for over 180 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution: Soft Close Soft closing inactive issues over a certain period label Sep 26, 2023
@Hotell Hotell reopened this Sep 27, 2023

Because this issue has not had activity for over 180 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants