ashtuchkin / iconv-lite

Convert character encodings in pure javascript.
MIT License
3.08k stars 281 forks source link

Unable to resolve module string_decoder could not be found #295

Open NguyenHuynhHuuTai opened 2 years ago

NguyenHuynhHuuTai commented 2 years ago

BUNDLE ./index.js

error: Error: Unable to resolve module string_decoder from C:\ProjectName\node_modules\iconv-lite\encodings\internal.js: string_decoder could not be found within the project or in these directories: node_modules

If you are sure the module exists, try these steps:

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-* 47 | 48 | // We use node.js internal decoder. Its signature is the same as ours.

    49 | var StringDecoder = require('string_decoder').StringDecoder; | ^ 50 | 51 | if (!StringDecoder.prototype.end) // Node v0.8 doesn't have this method. 52 | StringDecoder.prototype.end = function() {};

ashtuchkin commented 2 years ago

string_decoder is a core nodejs module ( https://nodejs.org/api/string_decoder.html). Please check your build environment.

On Fri, Mar 18, 2022, 03:21 NguyenHuynhHuuTai @.***> wrote:

BUNDLE ./index.js

error: Error: Unable to resolve module string_decoder from C:\ProjectName\node_modules\iconv-lite\encodings\internal.js: string_decoder could not be found within the project or in these directories: node_modules

If you are sure the module exists, try these steps:

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-* 47 | 48 | // We use node.js internal decoder. Its signature is the same as ours.

49 | var StringDecoder = require('string_decoder').StringDecoder; | ^ 50 | 51 | if (!StringDecoder.prototype.end) // Node v0.8 doesn't have this method. 52 | StringDecoder.prototype.end = function() {};

— Reply to this email directly, view it on GitHub https://github.com/ashtuchkin/iconv-lite/issues/295, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEZKHIK4BKIOQSFPSGJXFLVAQVILANCNFSM5RBA46CQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

forgetso commented 1 year ago

Try

const stringDecoderParent = require('string_decoder`)
const StringDecoder = stringDecoderParent.StringDecoder
yiqu commented 11 months ago

Install the vite node polyfills https://www.npmjs.com/package/vite-plugin-node-polyfills

Update your vite config: export default defineConfig({ plugins: [ nodePolyfills({ // To add only specific polyfills, add them here. If no option is passed, adds all polyfills include: ['string_decoder'], }), ], })