Replies: 1 comment 4 replies
-
At first glance, this might be caused by the default "ignore" option, which
is documented in our readme. It could be that the file is located at a
path which is ignored, so we do not attempt to transform it.
…On Thu, Mar 4, 2021, 5:15 PM Ionel lupu ***@***.***> wrote:
I am trying to create a CLI tool that will run typescript code instead of
Javascript (I really need to run typescript and not transpile the
typescript to javascript).
I run the Typescript code by registering the ts-node package manually:
/* index.js */
#!/usr/bin/env nodeconst path = require('path')
require('ts-node').register({
transpileOnly : true,
preferTsExts : true,})require('./cli')
/* cli.ts */const x: number = 123console.log(x)
/* package.json */
{
"name": "ionellupu-test-ts-node-cli",
"main": "index.js",
"bin": {
"test-ts-node-cli": "index.js"
},
"license": "ISC",
"dependencies": {
"ts-node": "^9.1.1",
"typescript": "^4.2.2"
}
}
I tested this by installing the package locally using npm link and it
works as expected:
$ test-ts-node-cli
123
The problem is when I am installing the CLI tool with npm install -g
ionellupu-test-ts-node-cli (after publishing it on npm and running npm
unlink) and run it, I get an error:
$ test-ts-node-cli
C:\Users\<username>\AppData\Roaming\npm\node_modules\ionellupu-test-ts-node-cli\cli.ts:1
const x: number = 123
^
SyntaxError: Missing initializer in const declaration
at wrapSafe (internal/modules/cjs/loader.js:979:16)
...
This is usually shown when the code is run with the javascript engine
instead of the ts-node compiler. This shows that the
require('ts-node').register() didn't work for some reason.
I prepared a test package
<https://www.npmjs.com/package/ionellupu-test-ts-node-cli> that we can
use to reproduce this problem.
One interesting this is that the script does run if I change the directory
to the node_modules of the npm:
$ where test-ts-node-cli
C:\Users\<username>\AppData\Roaming\npm\test-ts-node-cli
C:\Users\<username>\AppData\Roaming\npm\test-ts-node-cli.cmd
$ cd C:/Users/<username>/AppData/Roaming/npm/node_modules
$ pwd
/c/Users/<username>/AppData/Roaming/npm/node_modules
$ test-ts-node-cli
123
One other interesting this is that the app works if I run it directly with
node from C:\Users\<username>\AppData\Roaming\npm\node_modules:
$ pwd
/c/Users/<username>/AppData/Roaming/npm/node_modules
$ node ionellupu-test-ts-node-cli/index.js
123
But it doens't work if I run it from my home directory:
$ cd ~
$ pwd
/c/Users/<username>
$ node C:/Users/<username>/AppData/Roaming/npm/node_modules/ionellupu-test-ts-node-cli/index.js
C:\Users\<username>\AppData\Roaming\npm\node_modules\ionellupu-test-ts-node-cli\cli.ts:1
const x: number = 123
^
SyntaxError: Missing initializer in const declaration
It is really strange that in some cases it works and is others not.
Why is this happening and how can it be solved?
Why isn't ts-node.register working properly when installing the package
globally but works when using npm link?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1267>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OFFGVNJM2TVV56AHDDTCABA7ANCNFSM4YUCRG5A>
.
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create a CLI tool that will run typescript code instead of Javascript (I really need to run typescript and not transpile the typescript to javascript).
I run the Typescript code by registering the
ts-node
package manually:I tested this by installing the package locally using
npm link
and it works as expected:The problem is when I am installing the CLI tool with
npm install -g ionellupu-test-ts-node-cli
(after publishing it on npm and runningnpm unlink
) and run it, I get an error:This is usually shown when the code is run with the javascript engine instead of the ts-node compiler. This shows that the
require('ts-node').register()
didn't work for some reason.I prepared a test package that we can use to reproduce this problem.
One interesting this is that the script does run if I change the directory to the node_modules of the npm:
One other interesting this is that the app works if I run it directly with
node
fromC:\Users\<username>\AppData\Roaming\npm\node_modules
:But it doens't work if I run it from my home directory:
It is really strange that in some cases it works and is others not.
Why is this happening and how can it be solved?
Why isn't
ts-node.register
working properly when installing the package globally but works when usingnpm link
?Beta Was this translation helpful? Give feedback.
All reactions