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

Crash when minifying specific code with source maps (invalid type: map, expected a string) #8372

Closed
Frank3K opened this issue Dec 3, 2023 · 1 comment · Fixed by #8546
Closed
Assignees
Labels
Milestone

Comments

@Frank3K
Copy link

Frank3K commented Dec 3, 2023

Describe the bug

Bug Summary

The swc package is encountering an error during the minification process when handling specific input with an accompanying sourcemap. The error message is as follows:

[Error: invalid type: map, expected a string at line 1 column 3155233] {
  code: 'InvalidArg'
}

Background

I'm trying to speed up production builds of ember.js applications by trying to move from terser to swc for minification.

Reproduction

While minification seems to work fine with swc, working with sourcemaps does not. For this issue I created a new (empty) Ember.js application. Since the payloads are relatively large, I've set up a public repository showcasing the issue: swc-minify-crash-demo.

terser

Please note that terser works properly on the given input. A demo is also included in the repository.

Input code

Can be found on GitHub: vendor-4d35fc8b803beec7d53591943a61d748.js.

Config

.swcrc: N/A

minify options can be found on GitHub: vendor-4d35fc8b803beec7d53591943a61d748.json

Playground link (or link to the minimal reproduction)

https://github.com/Frank3K/swc-minify-crash-demo

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103
    CPU: (8 cores)
        Models: Apple M1

Binaries:
    Node: 18.15.0
    npm: 9.5.0
    Yarn: 1.22.19
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.3.100
    @swc/helpers: N/A
    @swc/types: 0.1.5
    

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

Next.js info:
    output: N/A

Expected behavior

The minifier exits properly with minified code and an accompanying source map.

Actual behavior

swc crashes with the following error:

[Error: invalid type: map, expected a string at line 1 column 3155233] {
  code: 'InvalidArg'
}

Version

1.3.100

Additional context

Happy to help with debugging, but I don't know where to start. I did try to start the script with SWC_DEBUG=1 node swc.mjs, but that did not lead to additional output.

@Frank3K Frank3K added the C-bug label Dec 3, 2023
@kdy1 kdy1 added this to the Planned milestone Dec 4, 2023
@kdy1 kdy1 self-assigned this Dec 4, 2023
kdy1 added a commit that referenced this issue Jan 24, 2024
**Description:**

- This PR fixes the source map generation when `inputSourceMap` is specified.
- This PR fixes `minify()` not accepting parsed source map in the option.


**Related issue:**

 - Closes #8372.
@kdy1 kdy1 modified the milestones: Planned, v1.3.106 Jan 24, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 23, 2024

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants