我读了TypeScript 模块解析的工作原理.
我有以下存储库:ts-di.编译目录结构后如下:
??? dist
? ??? annotations.d.ts
? ??? annotations.js
? ??? index.d.ts
? ??? index.js
? ??? injector.d.ts
? ??? injector.js
? ??? profiler.d.ts
? ??? profiler.js
? ??? providers.d.ts
? ??? providers.js
? ??? util.d.ts
? ??? util.js
??? LICENSE
??? package.json
??? README.md
??? src
? ??? annotations.ts
? ??? index.ts
? ??? injector.ts
? ??? profiler.ts
? ??? providers.ts
? ??? util.ts
??? tsconfig.json
Run Code Online (Sandbox Code Playgroud)
在我的package.json中,我写道"main": "dist/index.js".
在Node.js中一切正常,但TypeScript:
import {Injector} from …Run Code Online (Sandbox Code Playgroud) 我目前正在处理三个文件,分别是 index.js、index.main.js 和 app.js。我正在使用请求上下文从 index.main.js 中获取一个变量并将其传递给 index.js。
在 app.js(我在服务器文件夹中创建的文件)中,我有以下代码
//full code in app.js
const contextService = require("request-context");
const app = express();
app.use(contextService.middleware("request"));
Run Code Online (Sandbox Code Playgroud)
我试过运行以下命令
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
npm install -D @types/request-context
Run Code Online (Sandbox Code Playgroud)
并在导入前尝试使用
// @ts-ignore
Run Code Online (Sandbox Code Playgroud)
无济于事。
当我检查我的 app.js 时,我注意到“require”这个词上有三个点,它显示:
找不到模块“请求上下文”的声明文件。'/home/servertest/Desktop/folder/folder1/src/component_NodeJS/server/node_modules/request-context/lib/index.js' 隐式具有 'any' 类型。尝试npm install @types/request-context它是否存在或添加一个包含declare module 'request-context';ts(7016)的新声明 (.d.ts) 文件
在 index.main.js 我有以下内容
async function listFilesInDepth()
{
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'probizmy';
const [files] = await …Run Code Online (Sandbox Code Playgroud) 我正在尝试在一个简单的 Vue 应用程序中使用 vue-tabulator Vue 组件:https : //github.com/angeliski/vue-tabulator,该应用程序恰好是在 TypeScript 中编码的。
main.ts:
import Vue from 'vue'
import VueTabulator from 'vue-tabulator'
import App from './App.vue'
Vue.config.productionTip = false
Vue.use(VueTabulator)
new Vue({
render: h => h(App)
}).$mount('#app')
Run Code Online (Sandbox Code Playgroud)
App.ts:
import { Component, Vue } from 'vue-property-decorator'
@Component
export default class App extends Vue {}
Run Code Online (Sandbox Code Playgroud)
App.vue:
<template>
<div id="app">
<h1>Kewl</h1>
</div>
</template>
<style scoped>
</style>
<script lang="ts" src="./App.ts">
</script>
Run Code Online (Sandbox Code Playgroud)
运行我的应用程序时,npm run serve我有以下内容:
ERROR Failed to compile with 1 …Run Code Online (Sandbox Code Playgroud)