swc-project / swc-project/swc-node

swc-node issue importing files outside of root directory

Open
#703 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2k
Forks
95
Avg merge
14d 11h
Merged PRs (30d)
1

Description

Describe the bug

swc-node throws a SyntaxError and crashes when importing files from outside the directory, even if included in the tsconfig files property.

This works with both tsc and ts-node.

I did look for any swc configuration options that might affect this, but didn't find anything that seemed relevant or that helped, but it's possible I'm just missing something in the config here.

See this repo for a basic example: https://github.com/kg-jcaron/swc-issue-repro

Thanks!

Input code

No response

Config

No response

Playground link

No response

Expected behavior

I expect swc-node to match the behaviour of tsc and ts-node and run without errors.

Actual behavior

Throws a SyntaxError and crashes:

export const someImportedValue = "hello world";
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1094:15)
    at Module._compile (node:internal/modules/cjs/loader:1129:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
    at Object.newLoader [as .ts] (/Users/xxxx/Documents/repos/swc-node-issue/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:1043:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1067:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/xxxx/Documents/repos/swc-node-issue/primary/index.ts:6:18)
Version

1.3.38

Additional context

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked swc-issue-repro with swc-node 1.3.38 and compare its handling of the outside-root import with tsc and ts-node. Trace the relevant swc-node loading behavior from that reproduction; done means the example runs without the SyntaxError and matches the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.