本人用react,今天使用了一个setInterval,但是运行之后一直报错,信息如下:
Module not found: Error: Can't resolve 'timers' in 'E:\project\\client\src'
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: { "timers": require.resolve("timers-browserify") }'
- install 'timers-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "timers": false }
解决步骤:
- yarn add timers-browserify
- yarn eject暴露webpack配置,会在根目录下生成config文件夹
- 找到webpack.config.js文件,找到return里面的resolve,添加:
fallback: { "timers": require.resolve('timers-browserify') }
4.重新编译,成功启动