Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve module string_decoder could not be found #295

Open
NguyenHuynhHuuTai opened this issue Mar 18, 2022 · 3 comments
Open

Comments

@NguyenHuynhHuuTai
Copy link

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
Copy link
Owner

ashtuchkin commented Mar 18, 2022 via email

@forgetso
Copy link

forgetso commented Sep 7, 2023

Try

const stringDecoderParent = require('string_decoder`)
const StringDecoder = stringDecoderParent.StringDecoder

@yiqu
Copy link

yiqu commented Dec 20, 2023

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'],
}),
],
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants