Error including module with webpack
See original GitHub issueI am simply importing the library into my webpack project, but am receiving an error. I’m not even actually using the library, just importing it like this:
import helpers from 'handlebars-helpers';
When webpack bundles my files, I get the following error:
Module not found: Error: Can't resolve 'fs' in '/Users/me/dev/project/node_modules/handlebars-helpers/lib' resolve 'fs' in '/Users/me/dev/project/node_modules/handlebars-helpers/lib'
Parsed request is a module
using description file: /Users/me/dev/project/node_modules/handlebars-helpers/package.json (relative path: ./lib)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /Users/me/dev/project/node_modules/handlebars-helpers/package.json (relative path: ./lib)
resolve as module
/Users/me/dev/project/node_modules/handlebars-helpers/lib/node_modules doesn't exist or is not a directory
/Users/me/dev/project/node_modules/node_modules doesn't exist or is not a directory
/Users/me/dev/node_modules doesn't exist or is not a directory
/Users/me/node_modules doesn't exist or is not a directory
/Users/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /Users/me/dev/project/node_modules/handlebars-helpers/node_modules
using description file: /Users/me/dev/project/node_modules/handlebars-helpers/package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /Users/me/dev/project/node_modules/handlebars-helpers/package.json (relative path: ./node_modules)
using description file: /Users/me/dev/project/node_modules/handlebars-helpers/package.json (relative path: ./node_modules/fs)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/handlebars-helpers/node_modules/fs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/handlebars-helpers/node_modules/fs.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/handlebars-helpers/node_modules/fs.json doesn't exist
as directory
/Users/me/dev/project/node_modules/handlebars-helpers/node_modules/fs doesn't exist
looking for modules in /Users/me/dev/project/node_modules
using description file: /Users/me/dev/project/package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /Users/me/dev/project/package.json (relative path: ./node_modules)
using description file: /Users/me/dev/project/package.json (relative path: ./node_modules/fs)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/fs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/fs.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/Users/me/dev/project/node_modules/fs.json doesn't exist
as directory
/Users/me/dev/project/node_modules/fs doesn't exist
If I remove the import statement, the error goes away. Am I missing something obvious here or is there a bug in the library?
I’m using Node v7.9.0, webpack version 3.12.0, and handlebars-helpers version 0.10.0.
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (23 by maintainers)
Top Results From Across the Web
Error finding core node modules during webpack build in ...
Those node dependencies were not included by webpack by default. I needed to add target: "node" property in webpack.config.js.
Read more >Output - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >How to fix Error: cannot find module "webpack" - Educative.io
Solution · 1. Install webpack in the local app folder · 2. Link webpack to your project.
Read more >How to configure CSS Modules for webpack - LogRocket Blog
... CSS Modules and Webpack in this handy tutorial and demo app build. ... an app to escape CSS's notoriously tricky global scope...
Read more >How to configure CSS and CSS modules in webpack
You would get this error even though you had configured a loader for SVG files. Avoid weird erros like that by always using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@flyingL123 I got it working with the following
webpack.config.js
:and the
src/index.js
looks like this:This comment from @spplante helped a lot.
Awesome!
When bundling
handlebars
andhandlebars-helpers
only, I’ve usually seen the size be around 1 - 1.2MB, so there might be a configuration setting or plugin for reducing that.I’m going to close this issue since bundling is working with the latest webpack. I’ll be opening an issue on
log-utils
to remind myself (or anyone else) to update it based on what we’ve found here.