resolveJsonModule不能与Angular 10一起使用吗? [英] resolveJsonModule not functioning with Angular 10?

查看:157
本文介绍了resolveJsonModule不能与Angular 10一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个全新的Angular 10项目的资产文件夹中有一个基本的JSON文件.
角CLI:10.0.1节点:14.5.0操作系统:win32 x64 TSC版本3.9.5.在我的tsconfig.json中,

I have a basic JSON file in my assets folder of a brand new Angular 10 project.
Angular CLI: 10.0.1 Node: 14.5.0 OS: win32 x64 TSC version 3.9.5. In my tsconfig.json I have

  "compilerOptions": {
    "module": "commonjs",
    "resolveJsonModule": true,
    "esModuleInterop": true
  }

我已经多次重新启动vscode,并尝试从vscode终端,powershell窗口和bash终端进行编译,所有这些都返回相同的消息:考虑使用'--resolveJsonModule'导入带有'.json'的模块扩展名".我尝试使用不同选项的多个组合进行编译.此时,我想知道是否应该重新启动该项目并简单地降级我的Angular版本?

I have restarted vscode multiple times, and tried compiling from the vscode terminal, a powershell window, and a bash terminal, all returning the same message: "Consider using '--resolveJsonModule' to import module with '.json' extension". I have tried compiling with multiple combinations of different options. At this point I'm wondering if I should restart this project and simply downgrade my version of Angular?

推荐答案

在Angular版本10中,我们有3个"tsconfig"文件.

In Angular version 10 we have 3 "tsconfig" files.

您必须添加"resolveJsonModule";和"esModuleInterop""tsconfig.app.json"中的选项文件在"compilerOptions"内部.

You have to add "resolveJsonModule" and "esModuleInterop" options in the "tsconfig.app.json" file inside the "compilerOptions".

文件应如下所示:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

这篇关于resolveJsonModule不能与Angular 10一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆