[英]React.js app works fine in development mode but has errors after building (production mode)
Well, it's have been hours I'm trying to find out why I got this error (only in when running build):好吧,我已经花了几个小时试图找出为什么会出现此错误(仅在运行构建时):
Current directory is MySuperProject/src/Components/
Other non usefull files and directories are omitted.
.
├── Rentals
│ ├── modals
│ │ └── AddRentalModal.js Not usefull here
│ ├── RentalListItem.js https://pastebin.com/QSBncsHw
│ └── RentalsList.js https://pastebin.com/QufkCm85
├── Table
│ ├── Table.js https://pastebin.com/sq1jBPg1
└── Utils
└── axios.util.js Not usefull here, axios setting
In my main file, RentalsList.js, I:在我的主文件 RentalsList.js 中,我:
Table component is called like that:表组件是这样调用的:
<Table
columns={columns} // Columns of my table
datas={this.state.rentals} // Data I got from my API
TableItem={RentalListItem} // TableItem which is imported from ./RentalListItem.js
/>
Here is an example of datas returned by API:以下是 API 返回的数据示例:
[
{
"name":"Some name",
"ref":"AB01234",
"availability_date": 1605237860,
"cost": 123.45,
"type": 0,
"status": "Available",
"_id":"5f667cb47919fda09795ccad",
"address":{
"number": 1,
"way_type": "street",
"way_name": "name",
"postal_code": 12345,
"city": "StackyCity",
"_id":"5fadfc0e2add5eb934c497bb"
},
"added_by":{
"firstname":"Me",
"lastname":"Andmyself",
"_id":"5fac8ca0b86ee219381252eb",
"agency":{
"ref": "CD56789",
"name": "agency name",
"email": "an@email.com",
"_id":"5fac8f3db86ee219381252ec"
}
}
}
]
I don't have any error while running it under development mode.在开发模式下运行它时没有任何错误。 Indeed, I only have this error after building my code (for production environment)
事实上,我只有在构建我的代码后才会出现这个错误(用于生产环境)
Why do I get this error in production mode?为什么在生产模式下会出现此错误?
I noticed that after yarn build
, my componenent RentalListItem is rendered as a function t(e) but when I try to call it as a function it tells me that's a class. Well:)我注意到在
yarn build
之后,我的组件 RentalListItem 呈现为 function t(e) 但是当我尝试将其称为 function 时,它告诉我这是一个 class。嗯:)
When calling directly RentalListItem as a component on RentalsList I have no error当直接调用 RentalListItem 作为 RentalsList 上的组件时,我没有错误
In Table.js, this.props.TableItem seems to be well defined when it's called在 Table.js 中,this.props.TableItem 在调用时似乎定义明确
I suspect it's related to this JSX:我怀疑它与这个 JSX 有关:
<this.props.TableItem index={index} ... />
Try writing it like this:尝试这样写:
const TableItem = this.props.TableItem
...
<TableItem index={index} ... />
I believe your code is valid JSX, but it's not common to use dot notation like that, and my theory is that some part of the build process transforms it incorrectly.我相信您的代码是有效的 JSX,但像那样使用点符号并不常见,我的理论是构建过程的某些部分错误地转换了它。 In order to understand exactly what is causing this, we'd need to know what your build setup looks like.
为了准确了解是什么导致了这种情况,我们需要知道您的构建设置是什么样的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.