UPDATE:
Even with ts-node --files node_modules/typescript/lib/lib.d.ts ./lib/foo.ts
I'm still unable to get this to work.
ORIGINAL:
I have this simple file called foo.ts
that I'm trying to process with ts-node.
export class foo extends HTMLElement {
hello() {
console.log("hello")
}
}
const f = new foo();
f.hello();
When I rung ts-node ./lib/foo.ts
the library returns the following error:
/Users/haroldcampbell/work/go/src/groundtap/library/lib/foo.ts:1
export class foo extends HTMLElement {
^
ReferenceError: HTMLElement is not defined
at Object.<anonymous> (/Users/haroldcampbell/work/go/src/groundtap/library/lib/foo.ts:1:26)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
// truncated for brevity...
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at main (/usr/local/lib/node_modules/ts-node/src/bin.ts:198:14)
at Object.<anonymous> (/usr/local/lib/node_modules/ts-node/src/bin.ts:288:3)
The challenge is that it can't locate the typescript bindings which are in the node_modules/typescript/lib/lib.d.ts file
I've tried various other version of calling ts-node with no luck. For example:
- ts-node -r node_modules/typescript/lib/lib.d.ts ./lib/foo.ts
- npx ts-node -r node_modules/typescript/lib/lib.d.ts ./lib/foo.ts
Interestingly, Webpack doesn't have a problem processing the ./lib/foo.ts file, and does so without errors.
This is my tsconfig.json file:
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"strict": true,
"noImplicitAny": true,
"outDir": "./www/assets/dist/",
"lib": [
"es2016",
"dom"
]
},
"exclude": [
"node_modules",
"**/node_modules/*"
],
}
Any assistance in getting this to work would be greatly appreciated.
Ultimately, I want to be able to convert my .js
substack/tape test to .ts
files and run tape tests written with typescript on my typescript project files like so:
ts-node node_modules/tape/bin/tape ./lib/foo.test.ts