handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.96k stars 2.04k forks source link

Can't resolve 'fs' in '.../node_modules/handlebars/lib' #1890

Closed jinjin99 closed 2 years ago

jinjin99 commented 2 years ago

Throwing a error: Can't resolve 'fs' in '.../node_modules/handlebars/lib'when using package that depend on handlebars.

The project built with cra reports this error, but the project built with vite does not.

I get the following error simply by using import handlebars.

Failed to compile.

Module not found: Error: Can't resolve 'fs' in 'cra-demo/node_modules/handlebars/lib'
WARNING in ./node_modules/handlebars/lib/index.js 23:38-56
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./node_modules/handlebars/lib/index.js 24:2-20
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./node_modules/handlebars/lib/index.js 25:2-20
require.extensions is not supported by webpack. Use a loader instead.

ERROR in ./node_modules/handlebars/lib/index.js 15:11-24
Module not found: Error: Can't resolve 'fs' in 'cra-demo/node_modules/handlebars/lib'

webpack compiled with 1 error and 3 warnings
No issues found.

My index.js

import handlebars  from 'handlebars';

My package.json

   "handlebars": "^4.7.7"