ts-node

ts-node pass options to node

ぃ、小莉子 提交于 2021-02-18 22:28:01
问题 Is there a way to pass options to node when invoking ts-node? I am trying to use an experimental feature in node and it would be swell if it would work with ts-node. This is currently what I am doing: ts-node ./src/utils/repl.ts -- --experimental-repl-await 回答1: I got it to work this way: node --experimental-repl-await -r ts-node/register ./src/utils/repl.ts From the ts-node documentation: Note: If you need to use advanced node.js CLI arguments (e.g. --inspect ), use them with node -r ts-node

Node.js - SyntaxError: Unexpected token * when import express

落花浮王杯 提交于 2021-02-16 18:28:08
问题 node: v10.16.3 npm: 6.12.0 I got a error when I import express in node. I'm using this code https://github.com/angular-university/rxjs-course, look at server/server.ts . I run server.ts with $ ts-node ./server/server.ts The related code is: import * as express from 'express'; The error is: import * as express from 'express'; ^ SyntaxError: Unexpected token * at Module._compile (internal/modules/cjs/loader.js:723:23) at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:493:23

`Cannot use import statement outside a module` when combining RN and ts-node

爷,独闯天下 提交于 2021-01-29 21:46:38
问题 I created a small CLI tool to automate some process on my React Native project. Recently I had to update the RN from 0.61.4 to 0.63.2 to address some iOS issues. Since this update, the CLI is not working anymore. The errors are: yarn ts-node -r tsconfig-paths/register ./scripts/check import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo'; ^^^^^^ SyntaxError: Cannot use import statement outside a module and yarn ts-node -r esm -r tsconfig-paths

Extending built-in types in Typescript

不羁的心 提交于 2020-02-24 14:14:39
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

Extending built-in types in Typescript

匆匆过客 提交于 2020-02-24 14:11:47
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

Extending built-in types in Typescript

爱⌒轻易说出口 提交于 2020-02-24 14:10:48
问题 I have the following structure: project |- types |- global.d.ts |- string.d.ts |- wdio.d.ts |- src |- Models |- Resources |- Components |- Extensions |- string.ts |- ... |- tsconfig.json |- wdio.conf.js I try to extend the string's prototype with a function. I tried so far a lot of way, I found on several sites. But either the tsc gives me error, or the PHPStorm shows error message. // types/string.d.ts declare interface String { myCustomFn(text : string) : string; } // src/Extensions/string

Cannot find Typescript module even though tsc successfully manages to resolve it

自作多情 提交于 2020-01-29 09:11:27
问题 I have a Node.js project written in Typescript which is expected to run as a CLI, and am having trouble to import a module located out of the node_modules directory using an absolute path (relative paths work fine). It might be important to mention that I am using the oclif framework for building my CLI. My project is organized as follows: cli |--node_modules |--src |--my-module.ts |--subdir |--index.ts Within my-module.ts I have: export class MyClass { myClassFcn(s: string) { return 'result'

TypeError: Object prototype may only be an Object or null: undefined

家住魔仙堡 提交于 2020-01-24 03:13:06
问题 Below if I import Entity I get the posts's subject error (TypeError: Object prototype may only be an Object or null: undefined), but if I replace the import with the actual Entity declaration the code runs fine. Stackblitz demo here. This is Customer.ts in the form that produces the error when I run the code with ts-node : index.ts export { Customer } from "./Customer"; export { Entity } from "./Entity"; Customer.ts import { Entity } from "./index"; export class Customer extends Entity { sku:

What's the difference between tsc (TypeScript compiler) and ts-node?

天大地大妈咪最大 提交于 2019-12-30 06:31:44
问题 I'm very confused about the difference between tsc and ts-node . I'm learning TypeScript and I usually transpile server .ts files with tsc command. Now, I'm approaching nestjs framework, and I see that it uses ts-node . So what's the difference between the two? Which one should I use? 回答1: The main difference is that tsc transpile all the file according to your tsconfig. Instead, ts-node will start from the entry file and transpile the file step by step through the tree based on the import