Closed wheelerlaw closed 8 months ago
Seems like this might be related to this issue with ts-node: https://github.com/TypeStrong/ts-node/issues/1997
I ran your example (with the necessary modifications below) with node --loader=ts-node/esm example.ts
and it works as expected.
A few other things:
"type": "module"
in your package.json
file.node16
, nodenext
or bundler
in your tsconfig.json
file.I wonder if this is related to the issue I'm having in React - my project outputs in Common JS. I just implemented this package in a project a few days ago. It builds and compiles completely fine and runs in Storybook too. But when I run a Jest test on it, I get this strange error:
SyntaxError: Unexpected token 'export'
1 | import React, { useEffect, useState } from 'react';
2 | import i18next from 'i18next';
> 3 | import { mkConfig, generateCsv, download } from 'export-to-csv';
It seems to be saying that it doesn't like the term "export" at the beginning of the index.d.ts file. These are the imports in my TSX file, not in my Jest test file. I have other imports in various TSX files that start with the word export, so I don't understand why it doesn't like this one.
I'm not using ts-node anywhere in my project, but I am using ts-jest, so maybe it's a similar issue?
My tsconfig has "moduleResolution": "node"
because I'm using CJS, and also my package.json is not type:module, again due to using CJS, but that hasn't been a problem for any of the other packages that have a d.ts starting with export.
If I change moduleResolution to anything else it tells me it's invalid because I'm using CJS.
A-ha, and now I see why it doesn't work for me in CommonJS - right at the top of this package's description:
You can easily use this library in JavaScript as well. The bundle uses ES modules, which all modern browsers support.
I'll close this for now since this is largely out of my hands, and I haven't heard back from the OP. If the issue persists and more information comes to light, feel free to open another issue 😄
hi @dstorfer-cn, i hit the same issue as you, how do you eventually resolve the issue? im also using commonjs
hi @dstorfer-cn, i hit the same issue as you, how do you eventually resolve the issue? im also using commonjs
You may have missed my post right after that. Turns out this library uses ES modules, which I think are counter to functioning in commonJS.
Describe the bug The examples in the readme do not work in Typescript for nodejs.
To Reproduce Steps to reproduce the behavior:
touch example.ts
package.json
with the following in it:yarn
.node_modules/.bin/ts-node ./example.ts
Expected behavior The example would run.
Screenshots This is the output:
Desktop (please complete the following information):
Node.js v18.19.0,
ts-node
v10.9.2