ForInStatement 左侧的属性应为类型 [ "VariableDeclaration" , "LVal" ],但未定义 使用 --force 继续



我有一个大问题。我们使用angular.js application和maven来构建我们的应用程序。以前,当我们使用wer.json构建应用程序时,一切都可以正常工作。

昨天我们得到了这个错误

Warning: /builds/t2i/xecm/xecm-webapp/src/main/webapp/services/document-service.js: Property left of ForInStatement expected node to be of a type ["VariableDeclaration","LVal"] but instead got undefined Use --force to continue. Property left of ForInStatement expected node to be of a type ["VariableDeclaration","LVal"] but instead got undefined Use --force to continue.

我在谷歌上搜索了这个问题,我发现它在某种程度上与巴别塔的版本有关。但是我不明白它以前是怎么工作的,现在它不工作了。

我检查了,我100%确定我们没有改变任何依赖关系,不仅仅是babel,还有其他依赖关系。

在出现问题的文件document-service.js中,我们也没有做任何更改。最后一次修改是在2个月前,在这2个月里,一切正常,构建也通过了。

有什么问题吗?我从来没有遇到过这样奇怪的问题,我真的不知道我应该做什么,我应该检查什么来找到问题在哪里,我该如何解决这个问题…

这就是我的小屋。Json看起来像


{
"name": "${project.artifactId}",
"version": "{project.version}",
"homepage": "https://example.com/",
"appPath": "webapp",
"main": ["./${project.artifactId}.js"],
"private": true,
"dependencies": {
"json3": "~3.2.6",
"angular-resource": "1.6.4",
"angular-cookies": "1.6.4",
"angular-route": "1.6.4",
"angular-animate": "1.6.4",
"angular-sanitize": "1.6.4",
"angular-touch": "1.6.4",
"angular-gestures": "0.3.1",
"angular-spinner": "1.0.1",
"angular-css-injector": "1.4.0",
"angular-truncate": "*",
"angular-dynamic-locale": "~0.1.32",
"angular-once": "~0.1.8",
"angular-capitalize-filter": "~3.0.0",
"angular-ui-router": "1.0.5",
"xcomponent-widgets": "${project.build.directory}/${bower.components.dir}/xcomponent-widgets",
"angular": "1.6.4",
"ng-img-crop": "0.3.2",
"angular-bootstrap-switch": "0.5.2",
"angular-toastr": "2.1.1",
"angular-moment": "1.0.1",
"moment-timezone": "0.5.13",
"moment": "2.15.2",  
"ng-focus-if": "1.0.5",
"ng-file-upload": "12.2.3",
"ng-device-detector": "4.0.3",
"textAngular":"1.5.16",        
"angular-base64":"2.0.4",
"jspdf":"1.3.2",
"angular-clipboard":"1.5.0",
"ngclipboard":"1.1.1",
"angular-swx-session-storage":"1.0.2",
"angular-cache":"4.6.0",
"angular-highlightjs":"0.4.0",
"angularjs-slider": "6.4.3",
"angular-ui-select": "0.19.8",
"angular-bootstrap":"2.5.0"
},
"overrides": {
"bootstrap": {
"main": [
"less/bootstrap.less",
"dist/css/bootstrap.css",
"dist/js/bootstrap.js"
]
}
},
"devDependencies": {
"angular-mocks": "1.6.4",
"angular-scenario": "1.6.4",
"bootstrap": "~3.1.1"
},
"resolutions": {
"angular": "1.6.4",
"jquery": ">=1.9.0",
"bootstrap": "~3.1.1",
"moment": "2.15.2",
"ng-file-upload": "10.1.5"
}
}

我们也使用grunt,这是gruntfile-dev.js中babel配置的样子

babel: {
options: {
sourceMap: true,
presets: ['@babel/preset-env'],
sourceType: 'module'
},
dev: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.sources %>',
dest: '<%= yeoman.dev %>',
src: [
'**/*.js'
]
}]
}
},

检查你的代码"带有"var"的循环变量初始化,并将其替换为"在我的案例中,它解决了这个问题。

在花了一天的时间梳理了可能触发此错误消息的文件后,看起来实际导致此错误的是我们的一个组件JS文件末尾的CR-LF。然而,由于它们在某些ide中是不可见的,我们不得不使用消去过程来缩小范围。亲爱的读者,请记住这一点。

这个问题已经通过在for循环中添加let而不是var解决了。但为什么会出现这样的问题呢?

在我的例子中,问题是嵌套循环使用相同的变量名。

例如,

for (var i = 0; i < maxLenght; i++) {
for (var i = 0; i < maxCount; i++) {
}
}

将var更改为let可以解决问题,但更好的解决方法是更改嵌套变量的名称。

最新更新