Skip to content

panic: dual import triggering Option::unwrap on a None #1757

@robhowarth

Description

@robhowarth
  1. Source code

testlibrary.ts:

const aFunc = (a: number, b: number) => {
  return a + b;
};
export { aFunc };

testscript.ts:

import "testlibrary";
import { aFunc } from "testlibrary";

console.log("aFunc: ", aFunc(1,2));
  1. .swcrc file
{
  "env": {
    "targets": {
      "node": "16.2"
    }
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    }
  },
  "module": {
    "type": "commonjs"
  },
  "sourceMaps": "inline"
}
  1. Error message gained from npx swc --sync testscript.ts
    (--sync is required to get panic message)
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', ecmascript/transforms/module/src/util.rs:407:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
called `Option::unwrap()` on a `None` value
Error: Failed to compile 1 file with swc.
    at Object.assertCompilationResult (/Users/robhowarth/pricingmonkey/swcimport/node_modules/@swc/cli/lib/swc/util.js:162:15)
    at files (/Users/robhowarth/pricingmonkey/swcimport/node_modules/@swc/cli/lib/swc/file.js:176:18)
    at async default_1 (/Users/robhowarth/pricingmonkey/swcimport/node_modules/@swc/cli/lib/swc/file.js:190:9)
  1. Backtrace

(You can get it by invoking swc by setting an environment varaibleSWC_DEBUG to 1, invoke swc like SWC_DEBUG=1 npx swc foo.js on linux / darwin)

Backtrace:    0: _napi_register_module_v1
   1: <unknown>
   2: _rust_eh_personality
   3: _rust_eh_personality
   4: _rust_eh_personality
   5: _rust_eh_personality
   6: _rust_eh_personality
   7: _rust_eh_personality
   8: _rust_eh_personality
   9: _rust_eh_personality
  10: _rust_eh_personality
  11: _rust_eh_personality
  12: _rust_eh_personality
  13: _rust_eh_personality
  14: _rust_eh_personality
  15: _rust_eh_personality
  16: _rust_eh_personality
  17: _rust_eh_personality
  18: <unknown>
  19: __ZN6v8impl12_GLOBAL__N_123FunctionCallbackWrapper6InvokeERKN2v820FunctionCallbackInfoINS2_5ValueEEE
  20: __ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
  21: __ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
  22: __ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE

if you remove the first import, or remove the line in testscript.ts where aFunc is called then swc doesn't panic.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions