webpack-contrib / json-loader

json loader module for webpack - UNMAINTAINED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module not found: Error: Can't resolve 'foo.json'

sughanpandita opened this issue · comments

commented

'use strict';

const webpack = require("webpack");
const path = require('path');

module.exports = {
entry: {
app: './build/aws.js',
libraries: ['./src/libraries.js']
},

resolve: {

modules: [
  'node_modules',
  path.resolve('./build'),
  path.resolve('.'),
  path.resolve('../../../lib')
]

},

plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'libraries',
filename: 'lib.bundle.js'
})
],

output: {
path: './dist',
filename: 'bundle.js'
},
rules: [
{
test: /.json$/,
use: 'json-loader'
}
],
loaders:[

     { test: /vendor\/.+\.(jsx|js)$/,
         loader: 'imports?jQuery=jquery,$=jquery,this=>window',
     },

 ]

};

AWS.JSX
import foo from 'foo.json'

@sughanpandita webpack v1 or v2 ?

commented

Hi @michael-ciniawsky

"package.json"
{
"name": "yFilesForHTMLReactDemo",
"version": "1.0.0",
"private": true,
"dependencies": {
"imports-loader": "^0.7.1",
"jquery": "^3.2.1",
"json-loader": "^0.5.4",
"react": "^0.14.7",
"react-bootstrap-table": "^3.1.1",
"react-dock": "^0.2.3",
"react-dom": "^0.14.7",
"react-tabs": "^0.8.2"
},
"scripts": {
"babel": "babel src -d build",
"webpack": "webpack",
"build": "npm run babel && npm run webpack ",
"build:watch": "watch "npm run build" src"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-preset-react": "^6.5.0",
"json-loader": "^0.5.4",
"watch": "^0.17.1",
"webpack": "^2.2.1"
}
}

@sughanpandita You don't need json-loader anymore if webpack >= v2 :), can be safely removed

Module not found: Error: Can't resolve 'foo.json'

This can also be in relation to your current config.resolve setup

import foo from 'foo.json' => import foo from './foo.js' (foo.json => ./foo.json)

commented

Thanks @michael-ciniawsky it worked