Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file-loader with jest and webpack gives me a

I am using ace code editor package which uses a webpack-resolver.js file in its package that has inline file-loader! in each require statement e.g.

This works fine for my webpack config and everything builds fine when using it however when I go to use jest, it isn't recognizing the file-loader! and fails

require('file-loader!./src-noconflict/ext-beautify.js')

Is there something in the jest config to fix this?

I get the following error

 Cannot find module 'file-loader!./src-noconflict/ext-beautify.js' from 'webpack-resolver.js'
like image 737
Ruegen Avatar asked Nov 06 '19 23:11

Ruegen


People also ask

What is the use of loader in webpack?

They allow you to pre-process files as you import or “load” them. Thus, loaders are kind of like “tasks” in other build tools and provide a powerful way to handle front-end build steps. Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs.

Does jest need webpack?

Jest can be used in projects that use webpack to manage assets, styles, and compilation.


1 Answers

I added: "ace-builds": "<rootDir>/node_modules/ace-builds" in Jest moduleNameMapper, and it worked for me.

like image 97
BlueGlideExcavator Avatar answered Oct 16 '22 07:10

BlueGlideExcavator