json


Webpack imported JSON is undefined


I am using the new version of Webpack (2.5.1)
My webpack config is shown below:
const path = require('path');
const config = {
entry: './index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js'
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".json"]
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.json$/,
use: 'json-loader'
}
]
}
};
module.exports = config;
My index.ts contains the following:
import config from './config.json';
if (config) {
}
else {
console.log('Config is missing');
}
If I run node dist/index, it always outputs Config is missing
I am not sure why the imported object from the json file is ALWAYS UNDEFINED.
Here's the content of my config.json:
{
"connection": {
"host": "f",
"user": "f",
"password": "f",
"database": "f"
}
}
My file structure is:
dist
dist/index.js (generated when webpack transpiled typescript)
config.json
index.ts
webpack.config.js
package.json
typings.d.ts
tsconfig.json
My tsconfig.json is below:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true
},
"exclude": [
"node_modules",
"dist"
]
}

Related Links

How to get specific value from JSON in swift
Parsing object having property of type string that contains double quotes in it
Golang & mgo: How to create a generic entity with common fields like _id, creation time, and last update
Unexpected error within json babel 6.9
ASP.Net MVC how to display linq query data to an string array in view [duplicate]
How to create custom key in json response using golang
Convert JSON to Avro schema in Nodejs
restify jsonClient failing at post
Kendo Grid Date Filter wont work with my JSON data
JSONArray parsing laravel 4
How to manipulate native Json in WSO2 ESB?
How to read html entities using json response in Symfony2
Razor if statement with JSON [duplicate]
jSon script not displaying the table content
How to make Flask parse numbers in POSTed JSON data?
Post nested Json to spring controller using Jackson data binding

Categories

HOME
semantic-ui
json-ld
label
d
parse-server
apollo
vlc
orientation
laravel-4
console
algorithmic-trading
histogrammar
filter
browserify
ng-admin
aruco
window
jboss-eap-7
xul
finite-group-theory
netezza
ssms-2016
zoomcharts
atlassian-plugin-sdk
thumbnails
multicore
marathon
apple-tv
facebook4j
onsen-ui
rworldmap
osmdroid
guile
upnp
spring-data-neo4j
pentaho-report-designer
edge-detection
configure
positioning
roundcube
ioc-container
svnkit
percentage
helix-3d-toolkit
pycparser
viewstate
text-files
inkscape
freetts
polyfills
wcf-security
wsadmin
mediawiki-extensions
homekit
chunked-encoding
amazon-machine-learning
spell-checking
maintenance
windows-95
pluck
photography
sqlexception
autoresize
iron.io
restivejs
keycode
atlassian-crowd
pdflib
spring-ioc
bacnet
squirrel
string-parsing
date-format
picking
eml
git-rebase
magento-1.4
drf-nested-routers
schtasks.exe
ninject.web.mvc
selendroid
castle-windsor-3
twitter-rest-api
isml
custom-url
ticket-system
belongs-to
coin-flipping
broadcasting
json-patch
chrome-for-android
bfd
windows-update
surveyor-gem
shortcuts
fieldset
icsharpcode
deploying
macruby
unions
parameterization
law-of-demeter
cross-domain-policy
hashalgorithm
coff
galaxy-tab
smooth
out-of-browser
gwt-2.2-celltable
chdatastructures
idictionary
interface-design
cots

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App