Javascript npm编译错误(';';未定义)
我一直在更新js程序中的所有依赖项,但没有对任何组件进行任何更改。但是现在我跑的时候Javascript npm编译错误(';';未定义),javascript,node.js,reactjs,npm,react-bootstrap,Javascript,Node.js,Reactjs,Npm,React Bootstrap,我一直在更新js程序中的所有依赖项,但没有对任何组件进行任何更改。但是现在我跑的时候 npm run build 我的一个组件出现错误,上面写着: Failed to compile. ./src/components/DonationSummaryComponent.js Line 14: '_' is not defined no-undef Search for the keywords to learn more about each error. npm ERR! c
npm run build
我的一个组件出现错误,上面写着:
Failed to compile.
./src/components/DonationSummaryComponent.js
Line 14: '_' is not defined no-undef
Search for the keywords to learn more about each error.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Itay\AppData\Roaming\npm-cache\_logs\2018-09-17T08_25_54_825Z-debug.log
我试过了
npm i lodash
但这并没有解决问题
以下是有关错误的组件:
import React, { Component } from 'react';
import {Alert} from 'react-bootstrap';
import {MonthlyDonations} from './MonthlyDonationsComponent.js';
export class DonationSummary extends Component {
render() {
var monthsComponents = [];
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
if(this.props.yearData.length > 0){
var monthsdata = _.groupBy(this.props.yearData, function(dataEntry) {
return(monthNames[(new Date(dataEntry.donationDate)).getUTCMonth()]);
});
for (var monthName in monthsdata) {
if (monthsdata.hasOwnProperty(monthName)) {
monthsComponents.push(<MonthlyDonations key={monthName+this.props.year} monthName={monthName} monthData={monthsdata[monthName]}/>);
}
}
}
else{
monthsComponents.push(<Alert key="noDonations" bsStyle="info"> there are no donations to display </Alert> );
}
return(
<div>
{monthsComponents}
</div>
);
}
}
该错误可能与我将react引导react更新为最新版本(16.5.0)有关。这两个库都在该组件中使用。您需要在组件中导入lodash库 PFB工作代码
import React, { Component } from 'react';
import {Alert} from 'react-bootstrap';
import {MonthlyDonations} from './MonthlyDonationsComponent.js';
import _ from 'lodash';
export class DonationSummary extends Component {
render() {
var monthsComponents = [];
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
if(this.props.yearData.length > 0){
var monthsdata = _.groupBy(this.props.yearData, function(dataEntry) {
return(monthNames[(new Date(dataEntry.donationDate)).getUTCMonth()]);
});
for (var monthName in monthsdata) {
if (monthsdata.hasOwnProperty(monthName)) {
monthsComponents.push(<MonthlyDonations key={monthName+this.props.year} monthName={monthName} monthData={monthsdata[monthName]}/>);
}
}
}
else{
monthsComponents.push(<Alert key="noDonations" bsStyle="info"> there are no donations to display </Alert> );
}
return(
<div>
{monthsComponents}
</div>
);
}
}
import React,{Component}来自'React';
从“react bootstrap”导入{Alert};
从“./MonthlyDonationsComponent.js”导入{MonthlyDonations};
从“lodash”进口;
导出类DonationSummary扩展组件{
render(){
var-monthsComponents=[];
var monthNames=[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”,
“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”];
如果(this.props.yearData.length>0){
var monthsdata=uu.groupBy(this.props.yearData,函数(dataEntry){
返回(monthNames[(新日期(dataEntry.donationDate)).getUTCMonth());
});
用于(var monthName in MonthData){
if(monthsdata.hasOwnProperty(monthName)){
monthsComponents.push();
}
}
}
否则{
monthsComponents.push(没有可供展示的捐赠);
}
返回(
{monthsComponents}
);
}
}
您需要在组件中导入lodash库
PFB工作代码
import React, { Component } from 'react';
import {Alert} from 'react-bootstrap';
import {MonthlyDonations} from './MonthlyDonationsComponent.js';
import _ from 'lodash';
export class DonationSummary extends Component {
render() {
var monthsComponents = [];
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
if(this.props.yearData.length > 0){
var monthsdata = _.groupBy(this.props.yearData, function(dataEntry) {
return(monthNames[(new Date(dataEntry.donationDate)).getUTCMonth()]);
});
for (var monthName in monthsdata) {
if (monthsdata.hasOwnProperty(monthName)) {
monthsComponents.push(<MonthlyDonations key={monthName+this.props.year} monthName={monthName} monthData={monthsdata[monthName]}/>);
}
}
}
else{
monthsComponents.push(<Alert key="noDonations" bsStyle="info"> there are no donations to display </Alert> );
}
return(
<div>
{monthsComponents}
</div>
);
}
}
import React,{Component}来自'React';
从“react bootstrap”导入{Alert};
从“./MonthlyDonationsComponent.js”导入{MonthlyDonations};
从“lodash”进口;
导出类DonationSummary扩展组件{
render(){
var-monthsComponents=[];
var monthNames=[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”,
“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”];
如果(this.props.yearData.length>0){
var monthsdata=uu.groupBy(this.props.yearData,函数(dataEntry){
返回(monthNames[(新日期(dataEntry.donationDate)).getUTCMonth());
});
用于(var monthName in MonthData){
if(monthsdata.hasOwnProperty(monthName)){
monthsComponents.push();
}
}
}
否则{
monthsComponents.push(没有可供展示的捐赠);
}
返回(
{monthsComponents}
);
}
}
您没有在组件中导入lodash
你应该从“lodash”中添加
import代码>,它将工作您没有在组件中导入lodash
你应该从“lodash”中添加import代码>并且它将工作您需要导入lodash库
从“lodash”导入
我建议使用,这也将减少捆绑的大小。请安装并导入此软件包:
从“lodash.groupBy”导入groupBy
然后使用:
var monthsdata=groupBy(this.props.yearData,函数(数据输入){
您需要导入lodash库
从“lodash”导入
我建议使用,这也将减少捆绑包的大小。请安装此软件包并导入:
从“lodash.groupBy”导入groupBy
然后使用:
var monthsdata=groupBy(this.props.yearData,函数(数据输入){
你需要从“lodash”导入lodash库作为导入;是的,我的错。谢谢!你需要从“lodash”导入lodash库作为导入;是的,我的错。谢谢!