我使用create-react-app
的typescript模板创建了一个新项目。我希望我的react应用订阅MQTT Broker。这就是为什么我使用了typescript mqtt
库。我遵循了文档,但在启动我的react应用后,我遇到了以下问题:
ERROR in ./node_modules/mqtt/lib/connect/index.js 5:12-26
Module not found: Error: Can't resolve 'url' in '/Users/test/Code/mqtt-subscriber/node_modules/mqtt/lib/connect'
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: { "url": require.resolve("url/") }'
- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "url": false }
使用的版本为:
"mqtt": "^4.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
你有什么办法解决这个问题吗?我没有webpack配置文件。
如果我安装url
包,我会得到其他错误:
Buffer is not defined 'url'5:12-26 Module not found
1条答案
按热度按时间xytpbqjk1#
这看起来像this github issue-尝试从
dist
导入:或使用mqtt-precompiled