在使用VSCode时使用typescript中的import语句导入json文件时,我有一些奇怪的行为.请注意,这不是打字稿本身只是VSCode突出显示的问题.
我编辑了我的tsconfig.json,在我的编译器选项中添加了值为true的resolveJsonModule和esModuleInterop,以便在typescript中导入json.
此外,我已将此软件包添加到我的项目 https://www.npmjs.com/package/json-d-ts ,并将一个typeRoots属性添加到tsconfig.json,其值为["node_modules/json-d-ts" ]
我已经在一个模块(在src/firebaseApp.ts中找到)中导入了json文件(在src/config/firebaseServiceKey.json中找到),该模块位于父目录中,因此导入如下所示:
import databaseUrl from "./config/firebaseDatabaseURL.json";
Run Code Online (Sandbox Code Playgroud)
VSCode不会抱怨此导入:
但是我有另一个模块在项目目录中的不同级别导入相同的文件,该模块位于test/utils.ts,其导入如下所示:
import serviceKey from "../src/config/firebaseServiceKey.json";
Run Code Online (Sandbox Code Playgroud)
这次VSCode似乎不喜欢相对导入并突出显示模块缺失:
任何想法如何修复配置VSCode来解决这个问题?
以下是运行tsc --traceResolution结果的相关部分:
======== Resolving module '../src/config/firebaseServiceKey.json' from '/home/jty/April2018/vs-server/test/utils.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module as file / folder, candidate module location '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json', target file type 'TypeScript'.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.ts' does not exist.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.tsx' does not exist.
File '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json.d.ts' does not exist.
Directory '/home/jty/April2018/vs-server/src/config/firebaseServiceKey.json' does not exist, skipping all lookups in it.
Loading module as file / folder, candidate …
Run Code Online (Sandbox Code Playgroud) 嗨,我有一个问题,当该项目包含另一个打字稿依赖时,通过firebase-tools将我的typescript express应用程序部署到firebase.在谷歌功能中运行时,构建过程可能出现问题.请注意,程序在本地按预期工作,这只是部署的问题.
这是MVE的回购:
https://github.com/jk89/baseRepo
这加载了两个依赖:
https://github.com/jk89/depRepo1
https://github.com/jk89/depRepo2
我从firebase-tools'firebase deploy'得到以下错误:
jty@carrot:~/April2018/typescript-min-ver/baseRepo$ firebase deploy
=== Deploying to 'pricecalculator-e88d6'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build
> base-repo@0.1.0 build /home/jty/April2018/typescript-min-ver/baseRepo
> npm run tslint && tsc --declaration
> base-repo@0.1.0 tslint /home/jty/April2018/typescript-min-ver/baseRepo
> tslint -c tslint.json -p tsconfig.json
? functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
? functions: all necessary APIs are enabled
i functions: preparing . directory for uploading...
i functions: packaged . (12.76 KB) …
Run Code Online (Sandbox Code Playgroud)