我在将json文件导入typescript时遇到问题。我已经根据约定配置了tsconfig.json,但是它仍然不能在environment.ts文件中工作,但是在environment.prod.ts文件中,导入可以正常工作
environment.ts
import { domain, clientId, audience, serverUrl } from '../../auth_config.json';
export const environment = {
production: false,
auth: {
domain,
clientId,
redirectUri: window.location.origin,
audience,
},
dev: {
serverUrl,
},
};错误-->找不到模块'../../auth_config.json‘。考虑使用'--resolveJsonModule‘导入带有'.json’扩展的模块(2732)
environment.prod.ts
import { domain, clientId, audience, serverUrl } from '../../auth_config.json';
export const environment = {
production: true,
auth: {
domain,
clientId,
redirectUri: window.location.origin,
audience,
},
dev: {
serverUrl,
},
};它的工作正常。
我的tsconfig.json
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [],
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true
},
}我已经好几天没有找到原因了。谢谢。
发布于 2020-10-20 13:49:43
在这里您可以看到错误。现在在控制台中标记它,而不是在文件中。

https://stackoverflow.com/questions/64433368
复制相似问题