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





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



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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế