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

swc-node issue importing files outside of root directory #703

Open
kg-jcaron opened this issue Mar 8, 2023 · 4 comments
Open

swc-node issue importing files outside of root directory #703

kg-jcaron opened this issue Mar 8, 2023 · 4 comments

Comments

@kg-jcaron
Copy link

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

@kdy1 kdy1 transferred this issue from swc-project/swc Mar 9, 2023
@LeonAlvarez
Copy link

had same issue with pnpm monorepo

@kvet
Copy link

kvet commented Jul 19, 2023

Experiencing the same issue

@mmmeff
Copy link

mmmeff commented Nov 7, 2023

A transpileModules feature would be excellent for monorepo support. Something similar to next-transpile-modules, basically.

@313364973
Copy link

same problem,i have ts project with client and server ,server import some client shared ts code,and have this issue

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

No branches or pull requests

5 participants