facebook / jscodeshift

A JavaScript codemod toolkit.

Home Page:https://jscodeshift.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URL transform doesn't work with TypeScript

emlai opened this issue · comments

I have a transform file written in TypeScript. It works when used as a local file (-t path/to/file) but not as a URL (-t https://...).

With a github enterprise raw file link like https://raw.github.path/to/repo/path/to/file.ts?token=GHSAT0AAAAAAAAA6BCXCCVMJWKCSGK3L3UQZA2ZLWQ, jscodeshift fails with the following error:

/private/var/folders/sy/sqk95ngs0b7bb6c3872cbvyc0000gn/T/jscodeshift2023222-6764-1d1j47d.za2t.ts?token=GHSAT0AAAAAAAAA6BCXCCVMJWKCSGK3L3UQZA2ZLWQ:8
import type {
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1159:20)
    at Module._compile (node:internal/modules/cjs/loader:1203:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1293:10)
    at Object.newLoader [as .js] (/Users/emlai/.npm/_npx/c5e6d14ea42cfa80/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:1096:32)
    at Module._load (node:internal/modules/cjs/loader:935:12)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/helpers:112:18)
    at setup (/Users/emlai/.npm/_npx/c5e6d14ea42cfa80/node_modules/jscodeshift/src/Worker.js:91:18)

When using a the url of the github "Raw" button, e.g. https://github.path/to/repo/raw/path/to/file.ts, I get the following error:

 ERR file/to/transform.tsx Transformation error (transform is not a function)
TypeError: transform is not a function

SyntaxError: Cannot use import statement outside a module

You must have using import without modules. I think you need to add "type": "module" in your package.json file. Or else you can use require for importing file

commented

@Charlygraphy23 .mts doesn't work too.