node-html-to-text icon indicating copy to clipboard operation
node-html-to-text copied to clipboard

Cannot resolve module 'fs'

Open liSong5713 opened this issue 8 years ago • 7 comments

HI
I npm html-to-text and import ,but there is an error Cannot resolve module 'fs' in xxxxxx/node_modules/.3.1.0@html-to-text/lib, please help fix it many thanks

liSong5713 avatar Feb 16 '17 06:02 liSong5713

Do you run html-to-text in the browser?

mlegenhausen avatar Feb 16 '17 07:02 mlegenhausen

Same problem here. I'm using node and just trying to use html-to-text with import htmlToText from 'html-to-text'. Here is the trace:

ERROR in ./~/html-to-text/lib/html-to-text.js
Module not found: Error: Can't resolve 'fs' in '/home/lize/Informatique/pellov/node_modules/html-to-text/lib'
 @ ./~/html-to-text/lib/html-to-text.js 1:9-22
 @ ./~/html-to-text/index.js
…

liZe avatar Feb 21 '17 02:02 liZe

@liZe again do you try to run html-to-text in the browser?

html-to-text does currently only work in server environments.

mlegenhausen avatar Feb 21 '17 07:02 mlegenhausen

again do you try to run html-to-text in the browser?

I do, sorry.

liZe avatar Feb 21 '17 08:02 liZe

Depending on the build tool you need to provide a mock implementation or for example in webpack you need to set node: { fs: 'empty' } in your webpack config. Maybe this Stack Overflow Issue can help further: http://stackoverflow.com/questions/39249237/node-cannot-find-module-fs-when-using-webpack

mlegenhausen avatar Feb 21 '17 15:02 mlegenhausen

Thanks a lot for the hints, it'll do the job for me!

liZe avatar Feb 23 '17 12:02 liZe

Our fork @ https://github.com/calcbench/node-html-to-text seems to run in the client with webpack/babel.

andrewkittredge avatar Feb 09 '18 15:02 andrewkittredge

Time to close this. CLI is moved to external package in version 9, so there are no node dependencies left in html-to-text. And even before now, people were using the package with web bundlers for quite a while. An issue with webpack 4 is hopefully resolved in version 9.

KillyMXI avatar Dec 03 '22 12:12 KillyMXI