Linked Questions
35 questions linked to/from Importing JSON file in TypeScript
1
vote
1
answer
905
views
How to read json data using typescript? [duplicate]
I am trying to read data from config file, but it always returns empty. Do you have any idea what is implemented wrong here? I have added typing.d.ts:
declare module "*.json" {
const value: any;
...
0
votes
0
answers
76
views
How to import a json file in typescript? [duplicate]
I have a json file say data.json,
[
{
"page" : "First" ,
"subpage" : "FirstA",
"title" : [
{
"...
118
votes
13
answers
135k
views
Error: Should not import the named export 'version' (imported as 'version')
I have an ejected create-react-app project. I am getting this error after updating it to webpack 5. It was working fine with webpack v4.41.5
OS: MacOS Catalina 10.15.7
node: v10.23.0
Error: Should ...
67
votes
6
answers
83k
views
Typescript compiler error when importing json file
So the code is simple:
calls.json
{"SERVER":{
"requests":{
"one":"1"
}
} }
file.ts
import json = require('../static/calls.json');
console.log(json.SERVER);
the generated javascript is ...
40
votes
3
answers
54k
views
require a json file results in an error: Cannot find module
In a nodej project open in VsCode with checkJs enabled, when a json file is required like
const myFile = require('./my-file.json')
This makes an error [ts] Cannot find module.
How is it possible ...
13
votes
4
answers
20k
views
Import JSON in Angular 7 project
In my Angular project I'm importing JSON files for my own little localization service. I'm using the method suggested here, updating my typings.d.ts to
declare module "*.json" {
const value: any;...
29
votes
3
answers
27k
views
Importing JSON as a type
How do I define the type for imported json? For example
{
"things": "foo"
}
interface Data {
things: String,
another?: String
}
import data from './data.json' // Should ...
8
votes
4
answers
17k
views
Error - Should not import the named export
I have updated my Angular project to version 12.0.5 and Typescript version to 4.3.4 and I am having trouble compiling the project.
Currently I get the following error without having made changes to ...
7
votes
4
answers
39k
views
Read local JSON file in typescript
How can I read a locally stored JSON file into a variable in typescript? I have a json file of photos that looks like this:
[
{
"id": 1,
"camera": "",
...
15
votes
2
answers
12k
views
How do you import a JSON file with VueJS / Typescript?
I just created a clean VueJS new project and I can't get loading a JSON file to work.
Reproduction / Issue
For easy reproduction I've created a Github repo with my issue:
https://github.com/devedse/...
13
votes
1
answer
23k
views
Purpose of "resolveJsonModule"?
The setting I am referencing is shown in the snippet bellow
{
"compilerOptions": {
"resolveJsonModule": true,
}
}
I don't really understand why TS language engineers would ...
5
votes
2
answers
10k
views
Cannot find module on import with local JSON file
I have this simple angular project and I'm having trouble importing a local json file that I created. Here's the JSON file:
{
"id": 1,
"firstName": "Uziel",
"lastName": "Cabanban",
"...
1
vote
4
answers
9k
views
Angular 2 : Define global constants for api endpoints
I am new in Angular2. I would like to have a single class or a configuration file having all my API endpoints (allowing parameters and such in the different routes) that I could inject in all my ...
5
votes
2
answers
7k
views
Importing static JSON in create-react-app + typescript
I am learning typescript and currently trying to import simple json file which I store locally in the project bootstrapped with create-react-app.
data.json looks like this:
{
"test": "123",
}
In ...
5
votes
3
answers
6k
views
Loading JSON Without an HTTP Request
I am working on a project using Angular 4, NPM, Node.js, and the Angular CLI.
I have a rather unusual need to load JSON into an Angular service (using an @Injectable) without an HTTP request, i.e. it ...