reactjsshapefile

Nodebuffer is not supported by this platform


My code is running into a Nodebuffer that is not supported by this platform error.

Full error message:

node buffer is not supported by this platform in reacts, type of file reader. the result is ArrayBuffer(55826922)

Code:

import * as shp from 'shpjs'

shp(fileReader.result) // generate this error 

Any help will be appreciated


Solution

  • 1) npm install -S buffer
    2) // vue.config.js
    const { ProvidePlugin } = require('webpack');
    
    module.exports = {
      configureWebpack: {
        resolve: {
          fallback: {
            buffer: require.resolve('buffer/'),
          },
        },
        plugins: [
          new ProvidePlugin({
            Buffer: ['buffer', 'Buffer'],
          }),
        ],
      },
    };