我们相信:世界是美好的,你是我也是。平行空间的世界里面,不同版本的生活也在继续...

说是webpack的警告信息,实际上归属是babel,只不过是在webpack打包的时候显示出来罢了。警告信息是大段英文,主要内容就是提示某个库不再维护,所以目前的项目依赖关系有些不稳定,大意如此。

苏南大叔:webpack打包,plugin-proposal-private-property-in-object - webpack打包,plugin-proposal-private-property-in-object
webpack打包,plugin-proposal-private-property-in-object(图3-1)

苏南大叔的“程序如此灵动”博客,记录苏南大叔的编程心得体会。本文测试环境:nodejs@20.18.0create-react-app@5.0.1react-router-dom@6.27.0react@18.3.1express@4.21.1webpack-cli@5.1.4@babel/plugin-proposal-private-property-in-object@7.21.11

背景信息

通过create-react-app的项目里的webpack,打包各种ssr的文件,在打包的时候的警告信息输出。不过,不管是打包客户端还是打包服务器端,都有这样的黄色警告信息输出。内容如下:

One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.

babel-preset-react-app is part of the create-react-app project, which
is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.

苏南大叔:webpack打包,plugin-proposal-private-property-in-object - babel-plugin-warning
webpack打包,plugin-proposal-private-property-in-object(图3-2)

这个时候的babelpresets里面,设置是:

presets: ["react-app", "@babel/preset-env"],

解决方案

解决方案特别简单,安装@babel/plugin-proposal-private-property-in-object即可。

npm i @babel/plugin-proposal-private-property-in-object -D

安装成功后,再次执行webpack命令,来打包对应的.js文件,就不会再显示这些奇怪的黄色警告信息了。

苏南大叔:webpack打包,plugin-proposal-private-property-in-object - warning信息消失
webpack打包,plugin-proposal-private-property-in-object(图3-3)

结语

更多苏南大叔的webpack经验文章,请点击:

如果本文对您有帮助,或者节约了您的时间,欢迎打赏瓶饮料,建立下友谊关系。
本博客不欢迎:各种镜像采集行为。请尊重原创文章内容,转载请保留作者链接。

 【福利】 腾讯云最新爆款活动!1核2G云服务器首年50元!

 【源码】本文代码片段及相关软件,请点此获取更多信息

 【绝密】秘籍文章入口,仅传授于有缘之人   webpack