【问题标题】:Migrating to Vite: Uncaught TypeError: Cannot read property 'attrs' of undefined迁移到 Vite:未捕获的类型错误:无法读取未定义的属性“attrs”
【发布时间】:2021-06-01 08:22:25
【问题描述】:

出于开发环境中性能的原因,我正在尝试将大型应用程序从 create-react-app 迁移到 Vite.js。

我遵循了这个指南:https://phelipetls.github.io/posts/migrating-from-cra-to-vite/

这是详细的错误:

Uncaught TypeError: Cannot read property 'attrs' of undefined
    at node_modules/styled-bootstrap-grid/dist/components/Container/Container.js (Container.js:68)
    at __require2 (chunk-VZ7BJMYF.js?v=f5540ad4:17)
    at node_modules/styled-bootstrap-grid/dist/components/Container/index.js (index.js:27)
    at __require2 (chunk-VZ7BJMYF.js?v=f5540ad4:17)
    at node_modules/styled-bootstrap-grid/dist/index.js (index.js:53)
    at __require2 (chunk-VZ7BJMYF.js?v=f5540ad4:17)
    at dep:styled-bootstrap-grid:1
node_modules/styled-bootstrap-grid/dist/components/Container/Container.js @ Container.js:68
__require2 @ chunk-VZ7BJMYF.js?v=f5540ad4:17
node_modules/styled-bootstrap-grid/dist/components/Container/index.js @ index.js:27
__require2 @ chunk-VZ7BJMYF.js?v=f5540ad4:17
node_modules/styled-bootstrap-grid/dist/index.js @ index.js:53
__require2 @ chunk-VZ7BJMYF.js?v=f5540ad4:17
(anonymous) @ dep:styled-bootstrap-grid:1
injector.js:239 

我该如何调试呢?有什么建议吗?

提前致谢!

M

【问题讨论】:

    标签: javascript reactjs create-react-app vite


    【解决方案1】:

    似乎是 CommonJS 语法错误,因为 vite 不支持 CommonJS 语法。可以尝试使用vite插件vite-plugin-commonjs

    顺便说一句,

    https://github.com/originjs/webpack-to-vite

    这是我在转换旧项目时搜索错误消息时发现的一个github项目。它列出了一些转换项和错误修复方法。它甚至可以一键将旧项目转换为 vite 项目。不错,推荐!

    【讨论】:

    • 哇!太酷了,谢谢!我正在尝试使用您链接的工具,但我收到此错误env: node\r: No such file or directory,您遇到了吗?这是我尝试运行的命令webpack-to-vite -t webpack -d my-project
    • 不,我没有。最好的方法是向工具仓库提交问题。能否提供一个项目来重现和完整的日志记录,好吗?我会努力解决的
    猜你喜欢
    • 2021-12-22
    • 2015-01-06
    • 2017-07-26
    • 2019-02-26
    • 2021-12-25
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多