使用skywalking-client-js报错 webpack相关

使用skywalking-client-js报错 webpack相关

webpack5构建的项目中引入了skywalking-client-js,在使用时项目编译报错

error  in ./node_modules/skywalking-client-js/lib/index.js

Module not found: Error: Can't resolve 'buffer' in 'E:\project\node_modules\skywalking-client-js\lib'

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 }

skywalking-client-js引入的版本为0.6.0,webpack使用的版本是5.37.0,而项目中的webpack版本是5.36.2。看似都是webapck5,为什么控制台却报错webpack版本低于5?


回答:

问题已处理。感谢@jsdeferred 提供了思路。

webpack4默认有配置node.buffer,webpack5已更改node的配置,不再支持node.buffer,而是通过ProvidePlugin配置,new webpack.ProvidePlugin({ Buffer: ["buffer", "Buffer"] })另外还需手动安装buffer这个依赖,否则即使注入变量也找不到对应模块。

以上是 使用skywalking-client-js报错 webpack相关 的全部内容, 来源链接: utcz.com/p/935893.html

回到顶部