Json file was not found by webpack
Json file was not found by webpack
I am developing a small personal project,
i need to import json files with webpack but impossible
package.json contain:
"webpack": "^4.17.1"
"json-loader": "^0.5.7",
webpack.config.js contain
test: /.json$/, use: 'json-loader' ,
I dont know what vs code tell me this issue
import * as data from './loading.json';
- Cannot resolve module 'json' -
a question "Load static JSON file in Webpack" do not solve my problem and with json-loader or not this issue still present
json-loader
My issue still present
– terapha
Aug 26 at 20:16
1 Answer
1
As mentioned, you no longer need json-loader for .json
since webpack 2.0.0.
.json
However, if you are using json-loader because you don't want to bundle the json file, then I would recommend using one of the following solutions:
Use Copy Webpack Plugin to copy the json file into the build directory.
Use type = 'javascript/auto'
type = 'javascript/auto'
For example(note that this example uses file-loader instead of json-loader):
type: 'javascript/auto',
test: /.json$/,
use: [
loader: 'file-loader',
include: [path.resolve(__dirname, 'src')],
options:
name: '[name].[ext]'
]
Updated: Added include
. Remember to place the json file in the src folder.
include
For more information, please check out this page:
Webpack 4.0 file-loader json issue
I tested this solution but it did not work, I also tested the solution to rename the .json in something else it does not work either the file can not be found
– terapha
Aug 27 at 9:15
@terapha Then try adding
include: [path.resolve(__dirname, 'src')]
to the config file. Remember to place the json file in the src folder– Jonathan Tsai
Aug 28 at 2:34
include: [path.resolve(__dirname, 'src')]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of Load static JSON file in Webpack According to github.com/webpack-contrib/json-loader you don't have to use the
json-loader
when using webpack v2 and higher– SuperDJ
Aug 26 at 19:53