在我的项目文件夹中执行纱线安装并出现以下错误。
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module 'ts-node/register'
Require stack:
- internal/preload
?[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797
:15)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)?[39m
?[90m at Module.require (internal/modules/cjs/loader.js:852:19)?[39m
?[90m at Module._preloadModules (internal/modules/cjs/loader.js:1147:12)?[39m
?[90m at loadPreloadModules (internal/bootstrap/pre_execution.js:443:5)?[39m
?[90m at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:62:3
)?[39m
?[90m at internal/main/run_main_module.js:7:1?[39m {
code: ?[32m'MODULE_NOT_FOUND'?[39m,
requireStack: [ ?[32m'internal/preload'?[39m ]
}
Run Code Online (Sandbox Code Playgroud)
删除了node_module、yarn.lock 和node-cache。但没有成功。
此错误不是特定于项目的。如果我在系统中的任何地方运行yarn、node或npm,我都会遇到上述错误。我的节点和纱线包是否损坏?
我最近尝试将用 JavaScript 编写的 Webpack 配置迁移到 TypeScript。不幸的是我对此很挣扎。我已经为 webpack 编写了一个最小的配置文件来启动,因此缺少一些部分。我的webpack.config.ts看起来像这样:
import webpack from "webpack";
const config: webpack.Configuration = {
entry: {
bookmarklet: 'bookmarklet.ts'
},
output: {
filename: '[name].js',
path: __dirname + '/dist'
}
}
export default config;
Run Code Online (Sandbox Code Playgroud)
我有一个tsconfig.json其中包含:
{
"compilerOptions": {
"module": "ESNext",
"target": "ES6",
"lib": ["ES6", "dom"],
"strict": true,
"isolatedModules": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false
}
}
Run Code Online (Sandbox Code Playgroud)
其中package.json包含:
{
"name": "bookmarklets",
"version": "0.0.1",
"description": "A collection of …Run Code Online (Sandbox Code Playgroud) ts-node 似乎已安装,该包在 users/user/node_modules/ts-node 中可见,但是在命令行中输入 ts-node 或尝试运行命令时,我收到错误“zsh:找不到命令:ts -节点”。
通过 'sudo npm install -g ts-node' 安装;已经搜索了谷歌搜索的前 3-4 页,但没有解决方案。
在 MacBook 上,不确定需要移动什么/如何移动它以便系统识别它已安装。帮助将不胜感激。
对于我的项目 ci/cd,我运行tsc --noEmit以确保代码类型检查。然而,我有一些运行的脚本ts-node,最近我遇到了一个错误,tsc说我的代码有效但ts-node崩溃了(由于模块的时髦东西)。有没有一种方法可以让我不必使用tsc代理来检查ts-node类型检查/运行是否正确?
这些选项看起来都没有多大帮助:https://github.com/TypeStrong/ts-node#cli-flags
*.ts我在使用 ts-node运行文件时遇到问题。
我的项目的目录结构如下所示。
-- project dir
-- src
-- services
-- module1
-- file1.ts (classA)
-- file2.ts (classB)
-- index.ts (contains export statements like export * from file1.ts)
-- application.ts
Run Code Online (Sandbox Code Playgroud)
这是我在tsconfig.json文件中配置的内容。
{
"compilerOptions": {
"lib": [
"es2020",
"dom"
],
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"],
"@tests/*": ["tests/*"],
},
"module": "CommonJS",
"target": "es2020",
"strict": true,
"alwaysStrict": true,
"declaration": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noImplicitReturns": true,
"inlineSourceMap": true,
"inlineSources": …Run Code Online (Sandbox Code Playgroud) 我有一个用Typescript编写的Node.js项目,它应该作为CLI运行,并且无法node_modules使用绝对路径导入位于目录外的模块(相对路径工作正常).可能很重要的是,我正在使用oclif框架来构建我的CLI.
我的项目安排如下:
cli
|--node_modules
|--src
|--my-module.ts
|--subdir
|--index.ts
Run Code Online (Sandbox Code Playgroud)
在my-module.ts我有:
export class MyClass {
myClassFcn(s: string) {
return 'result'
}
}
Run Code Online (Sandbox Code Playgroud)
该index.ts脚本包含以下内容:
import {MyClass} = require('my-module')
Run Code Online (Sandbox Code Playgroud)
当我尝试用ts-node执行我的应用程序时,我明白了
(node:10423) [MODULE_NOT_FOUND] Error Plugin: cli: Cannot find module 'my-module'
module: @oclif/config@1.6.17
task: toCached
plugin: cli
root: /home/eschmidt/Workspace/cli
Error Plugin: cli: Cannot find module 'my-module'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/eschmidt/Workspace/cli/src/commands/create/index.ts:5:1)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Module.m._compile (/home/eschmidt/Workspace/cli/node_modules/ts-node/src/index.ts:403:23)
at …Run Code Online (Sandbox Code Playgroud) 我的文件src/auth/ManagementAPI.ts使用 Auth0。我需要使用我自己的声明文件并创建了src/@types/auth0.d.ts.
但是,当我运行时ts-node,出现此错误:
TSError: ? Unable to compile TypeScript:
auth/ManagementAPI.ts(1,69): error TS7016: Could not find a declaration file for module 'auth0'. '/Users/danrumney/WebstormProjects/ohana/node_modules/auth0/src/index.js' implicitly has an 'any' type.
Try `npm install @types/auth0` if it exists or add a new declaration (.d.ts) file containing `declare module 'auth0';
Run Code Online (Sandbox Code Playgroud)
我已经更新了我的tsconfig.json文件以包括:
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
Run Code Online (Sandbox Code Playgroud)
我的声明文件是这样的:
declare module 'auth0' {
/*...*/
}
Run Code Online (Sandbox Code Playgroud)
为什么这个声明没有被采纳?
我在这里创建了一个示例存储库:https : //bitbucket.org/ohanapediatrics/so-demo/src/master/
TS_NODE_PROJECT当 ts-node 用于使用 Mocha 进行测试时,我在使用 env 变量时遇到问题。
项目结构如下所示:
src/
main_test.ts
tsconfig.json
package.json
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我想使用异步函数,它需要"lib": ["es2018"]作为编译选项。
// src/main_test.ts
describe('', () => {
it('test', () => {
(async function() {})()
});
});
// src/tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"lib": ["es2018"]
},
"exclude": [
"../node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
为了运行测试,我使用了这个命令,但它会导致一个错误:
TS_NODE_PROJECT='src' && mocha --require ts-node/register src/*_test.ts
# TSError: ? Unable to compile TypeScript:
# error TS2468: Cannot find global value 'Promise'.
# src/main_test.ts(3,10): error TS2705: An async function …Run Code Online (Sandbox Code Playgroud) 我正在开始一个新项目,Typescript我想typescript使用制作节点服务器express。我一直在关注有关如何运行Typescript文件而不必在此链接中编译文件的教程:https : //medium.com/javascript-in-plain-english/typescript-with-node-and-express-js-为什么何时以及如何使用eb6bc73edd5d。
我现在面临的问题是,在执行运行的脚本时ts-node-dev,会引发错误:
> vidursyn@0.0.0 server:start /home/oscar/Documents/vidursyn
> ts-node-dev --respawn --transpileOnly ./src/server/app.ts
Using ts-node version 7.0.1, typescript version 3.2.4
/home/oscar/Documents/vidursyn/src/server/app.ts:1
(function (exports, require, module, __filename, __dirname) { import express from "express";
^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Object.obj.(anonymous function) [as runInThisContext] (/home/oscar/Documents/vidursyn/node_modules/ts-node-dev/lib/hook.js:30:19)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Module._compile (/home/oscar/Documents/vidursyn/node_modules/source-map-support/source-map-support.js:517:25)
at Module.m._compile (/tmp/ts-node-dev-hook-9240179406846312.js:56:25)
at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-9240179406846312.js:58:14) …Run Code Online (Sandbox Code Playgroud) 您好,我有以下打字稿代码:
import { getConnection } from "typeorm";
import { GraphQLClient } from "graphql-request";
import got from "got";
import database from "./utils/database";
...
Run Code Online (Sandbox Code Playgroud)
当我执行:
cross-env NODE_ENV=development ts-node src/scripts/createApp.ts http://localhost:3010/graphql
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
throw new TypeError(`${relative(cwd, fileName)}: Emit skipped`)
^
TypeError: src/scripts/utils/database.js: Emit skipped
Run Code Online (Sandbox Code Playgroud)
数据库.js
import { createConnection, getConnectionOptions, getConnection } from "typeorm";
export default {
async connect(): Promise<void> {
const connectionOptions = await getConnectionOptions(process.env.NODE_ENV);
await createConnection({
...connectionOptions,
name: "default",
});
},
disconnect(): Promise<void> {
return getConnection().close();
},
};
Run Code Online (Sandbox Code Playgroud)
错误在哪里?,我该如何解决?
谢谢
ts-node ×10
typescript ×7
node.js ×5
express ×1
javascript ×1
mocha.js ×1
node-modules ×1
npm ×1
oclif ×1
tsconfig ×1
webpack ×1
yarnpkg ×1