0
我想在我的一個.ts文件中導入JSON文件。但是,當我做一個require.I時,我得到一個運行時錯誤。在打字稿中導入JSON時出現問題
public serverConfiguration = require('./serverConfiguration.json');
這是我在.ts中添加我的JSON文件的方式。
在運行網頁,我收到以下錯誤:
Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/config/serverConfiguration.json.js
Error: XHR error (404 Not Found) loading http://localhost:3000/config/serverConfiguration.json.js
at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:698:29)
at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:265:35)
at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:154:47)
at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:335:33)
Error loading http://localhost:3000/config/serverConfiguration.json.js as "./serverConfiguration.json" from http://localhost:3000/config/config.js
at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:698:29)
at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:265:35)
at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:154:47)
at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:335:33)
Error loading http://localhost:3000/config/serverConfiguration.json.js as "./serverConfiguration.json" from http://localhost:3000/config/config.js
我已經在我的System.config.js中的條目,但仍沒有運氣。
packages: {
serverConfiguration:{
defaultExtension : 'json'
},
我已經嘗試導入JSON文件,但我相信,同樣不能做一個JSON文件。
在此先感謝。
@詹姆斯·唐納利....你能爲類似提供鏈接Question.I嘗試過,但沒有發現任何類似的東西。 – user3856563