You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the readme, ts-node registers itself for file endings .tsx?, i.e. .ts and .tsx. Therefore the behavior should be the same for both file endings.
Actual Behavior
SyntaxError: Cannot use import statement outside a module with.tsx file
Steps to reproduce the problem
# create a test.ts file
$ echo"import * as path from 'path'">> test.ts
$ echo"console.log(Object.keys(path))">> test.ts
# works as expected
$ ts-node test.ts
[
'resolve', 'normalize',
'isAbsolute', 'join',
'relative', 'toNamespacedPath',
'dirname', 'basename',
'extname', 'format',
'parse', 'sep',
'delimiter', 'win32',
'posix', '_makeLong'
]
# copy to test.tsx
$ cp test.ts test.tsx
# try running it with ts-node
$ ts-node test.tsx
(node:19628) Warning: To load an ES module, set"type": "module"in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\aval\tsdev\chroma.ts\ts-node-error\test.tsx:1
import * as path from 'path'
^^^^^^
SyntaxError: Cannot use import statement outside a module
...
# -O does nothing
$ ts-node -O "{\"module\":\"commonjs\"}" test.tsx
(node:1784) Warning: To load an ES module, set"type": "module"in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\aval\tsdev\chroma.ts\ts-node-error\test.tsx:1
import * as path from 'path'
^^^^^^
SyntaxError: Cannot use import statement outside a module
...
Minimal reproduction
see above
Specifications
ts-node v9.1.1
node v14.15.2
compiler v4.1.3
tsconfig.json, if you're using one: none, see above
Operating system and version:
If Windows, are you using WSL or WSL2?: no
The text was updated successfully, but these errors were encountered:
@cspotcode Figured it out too after I posted 😄. Having this work out of the box probably doesn't make sense, as TS itself requires the jsx optionto be set.
Expected Behavior
According to the readme, ts-node registers itself for file endings
.tsx?
, i.e..ts
and.tsx
. Therefore the behavior should be the same for both file endings.Actual Behavior
SyntaxError: Cannot use import statement outside a module
with.tsx fileSteps to reproduce the problem
Minimal reproduction
see above
Specifications
ts-node v9.1.1
node v14.15.2
compiler v4.1.3
tsconfig.json, if you're using one: none, see above
Operating system and version:
The text was updated successfully, but these errors were encountered: