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 evaluate a value as a variable in row returned by neo4j?
WSO2 ESB Custom Axis Module JSON Payload in MessageContext
Android - How can I access nested objects?
Json deserialization of Scala case objects with spray-json
JSON Structure/Syntax
What database model should be used with a bunch of different items?
JSON Property not binding to JSON.NET PropertyName in ASP.NET MVC 5 Post request
How to use Newtonsoft.Json as default in Asp.net Core Web Api?
Get product details in JSON format using REST API
Extract value from JSON
Get JSON stringify value
Express: Prevent bodyParser from parsing request
Nested arrays in json vs multiple separated json objects - performance
JSON object syntax
EXCEPTION: Response with status: 404 Not Found for URL / Angular2
How to use fetch to post with content-type of application/json

Categories

HOME
sql-server
jsf
google-cloud-bigtable
crate
vs-team-services
heap-memory
vlc
webdav
terrain
defragmentation
criteria
uiview
future
squarespace
typeahead
datagrip
zope
google-openid
primes
flexlm
multiple-columns
excel-2010
cruisecontrol.net
countif
piwik
jquery-scrollify
bootstrap-typeahead
rhandsontable
unpack
web-frontend
vcard
data-conversion
pitest
sharp
cell-array
pep8-assembly
lmdb
read-write
backup-strategies
google-drive-realtime-api
geopy
modelandview
viewstate
nlb
topic-modeling
deepstream.io
linq-to-entities
intellij-idea-2016
web-development-server
react-native-router-flux
ttcn
amd
php-ews
defold
nstouchbar
broadcast
livescribe
tcserver
pagefile
launch
infinite-scroll
efxclipse
typhoon
debugdiag
gitweb
elastix
function-fitting
datasnap
response-headers
futuretask
urn
risk-analysis
pyopengl
google-plus-one
virus
sortable
facebook-wall
getimagedata
lov
mimosa
dynamic-proxy
onselect
stagefright
digital-design
qt4.6
fieldset
template-haskell
cgpath
enumerators
icefaces-3
mpmovieplayer
separation-of-concerns
emacs23
executable-format
phpcrawl
pureftpd
exitstatus
trampolines
idictionary
iphone-sdk-3.2
oggvorbis
windows-controls
microsoft.ink
configurable
document-library

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