question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR in ./node_modules/safer-buffer/safer.js

See original GitHub issue

when I require iconv-lite and build ,I get the error,

ERROR in ./node_modules/safer-buffer/safer.js 5:13-30
Module not found: Error: Can't resolve 'buffer' in 'C:\Users\007\Desktop\mmd-play\node_modules\safer-buffer'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
        - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "buffer": false }
resolve 'buffer' in 'C:\Users\007\Desktop\mmd-play\node_modules\safer-buffer'
  Parsed request is a module
  using description file: C:\Users\007\Desktop\mmd-play\node_modules\safer-buffer\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      C:\Users\007\Desktop\mmd-play\node_modules\safer-buffer\node_modules doesn't exist or is not a directory
      C:\Users\007\Desktop\mmd-play\node_modules\node_modules doesn't exist or is not a directory
      looking for modules in C:\Users\007\Desktop\mmd-play\node_modules
        single file module
          using description file: C:\Users\007\Desktop\mmd-play\package.json (relative path: ./node_modules/buffer)
            no extension
              C:\Users\007\Desktop\mmd-play\node_modules\buffer doesn't exist
            .js
              C:\Users\007\Desktop\mmd-play\node_modules\buffer.js doesn't exist
            .json
              C:\Users\007\Desktop\mmd-play\node_modules\buffer.json doesn't exist
            .wasm
              C:\Users\007\Desktop\mmd-play\node_modules\buffer.wasm doesn't exist
        C:\Users\007\Desktop\mmd-play\node_modules\buffer doesn't exist
      C:\Users\007\Desktop\node_modules doesn't exist or is not a directory
      C:\Users\007\node_modules doesn't exist or is not a directory
      C:\Users\node_modules doesn't exist or is not a directory
      C:\node_modules doesn't exist or is not a directory
 @ ./node_modules/iconv-lite/lib/index.js 5:13-43
 @ ./src/component/model-upload.js 65:12-33
 @ ./src/views/contribute/index.js 70:0-55 303:42-53
 @ ./src/router/index.js
 @ ./src/App.js 39:0-39 57:42-51
 @ ./src/index.js 3:0-24 4:50-53

so I add resolve.fallback: { “buffer”: require.resolve(“buffer/”) } to webpack.config.js,but

[webpack-cli] Failed to load 'C:\Users\007\Desktop\mmd-play\webpack.config.js' config
[webpack-cli] Error: Cannot find module 'buffer/'
Require stack:
- C:\Users\007\Desktop\mmd-play\webpack.config.js
- C:\Users\007\Desktop\mmd-play\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\007\Desktop\mmd-play\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\007\Desktop\mmd-play\node_modules\webpack-cli\bin\cli.js
- C:\Users\007\Desktop\mmd-play\node_modules\webpack\bin\webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.resolve (C:\Users\007\Desktop\mmd-play\node_modules\v8-compile-cache\v8-compile-cache.js:164:23)
    at Object.<anonymous> (C:\Users\007\Desktop\mmd-play\webpack.config.js:25:31)
    at Module._compile (C:\Users\007\Desktop\mmd-play\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (C:\Users\007\Desktop\mmd-play\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at WebpackCLI.tryRequireThenImport (C:\Users\007\Desktop\mmd-play\node_modules\webpack-cli\lib\webpack-cli.js:32:22) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\007\\Desktop\\mmd-play\\webpack.config.js',
    'C:\\Users\\007\\Desktop\\mmd-play\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'C:\\Users\\007\\Desktop\\mmd-play\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'C:\\Users\\007\\Desktop\\mmd-play\\node_modules\\webpack-cli\\bin\\cli.js',
    'C:\\Users\\007\\Desktop\\mmd-play\\node_modules\\webpack\\bin\\webpack.js'
  ]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shuangovocommented, Aug 10, 2021

oh,It was build success just for its webpack version is 4, I got the error in version 5

0reactions
shuangovocommented, Aug 11, 2021

The problem is resolved.I’m stupid,I always thought the error Error: Cannot find module 'buffer/' ask me to npm i buffer/ ,however,the correct is npm i buffer.So in webpack5,we should npm i buffer and add a config into webpack.config.js

resolve: {
  fallback: {
    'buffer': require.resolve('buffer/')
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ExpressJs is return error `ERR_MODULE_NOT_FOUND` if ...
If someone is still searching, I got this error using node version 15, I was importing the files without the .js file extension, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found