question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve 'fs' with WebPack

See original GitHub issue

When I try to load ejs within a WebPack project with import ejs from 'ejs' I get:

Module not found: Error: Can't resolve 'fs' in 'node_modules/ejs/lib'

Is there something I need to do to make it work client-side or what? Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
airbladecommented, May 24, 2017

@mde Thanks to your comment I was able to get it working, actually in two ways.

First way: drop the built-and-minified JS file into my project and require('ejs') just before I want to use it. Then I can do ejs.render(string, data) etc. The only downside is I couldn’t figure out how to load up separate template files; but instead I can put templates in my html within <script type="x-template"></script> tags.

Second way: configure webpack with ejs-compiled-loader as a loader for *.ejs files, and then simply const template = require('some_template.ejs') where I want to use it. I don’t need a separate require('ejs').

Thanks for the help!

0reactions
mdecommented, May 23, 2017

The built-and-minified JS file in every release is now compiled with the Browserify --standalone flag, which should provide AMD support and ought to work with WebPack. If you’re using it client-side, that might be easier than trying to finagle the build yourself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'fs' in - Stack Overflow
I found a possible solution, that you have to put some configuration in one of the node_modules. But I think that is not...
Read more >
Can't resolve 'fs' when bundle with webpack #447 - GitHub
I got this error when using the "fetch" library from npm. At first I got the same error but with other packages (...
Read more >
Can't resolve 'fs' error in Next.js and WebPack - Nsikak Imoh
The Module not found: Can't resolve 'fs' in Next.js error occurs when you import a Node.js module that is not available in the...
Read more >
can't resolve fs in node_modules - You.com | The AI Search ...
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable...
Read more >
Module not found | Can't resolve 'fs' in Next js application
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found