简体   繁体   English

Vagrant和javascript错误可能是由于行尾

[英]Errors with Vagrant and javascript possibly due to line endings

I am trying to set up a Vagrant dev environment that I can re use. 我正在尝试建立一个我可以重用的Vagrant开发环境。 I am having a lot of problems using NPM and specifically Browserify. 使用NPM(尤其是Browserify)时遇到很多问题。

Whenever I run browserify to bundle js files. 每当我运行browserify捆绑js文件时。 It works ok the first time after git cloning my repo, but if I then edit the files on my windows machine (or my mac). git克隆我的仓库后,它第一次可以正常运行,但是如果我随后在Windows机器(或Mac)上编辑文件,则可以。 I start getting errors in javascript files: 我开始在javascript文件中出现错误:

Uncaught SyntaxError: Unexpected token ILLEGAL

I am sure this is to do with line endings but have so far been unable to fix it. 我敢肯定这与行尾有关,但到目前为止还无法解决。 I have tried setting git config settings as follows: 我尝试过如下设置git config设置:

git config --global core.autocrlf false

Have tried various values for the above command with no luck. 尝试了上述命令的各种值,但没有走运。 I also tried setting eol for file types within .gitattributes like this: 我还尝试过为.gitattributes中的文件类型设置eol,如下所示:

*.js text eol=lf * .js文字eol = lf

...but am now getting to the point where I am a bit lost. ...但是现在到了我有点迷路的地步。 Has anyone experienced similar issues and had any luck with a solution? 有没有人遇到过类似的问题,并且有解决方案的运气?

After pulling my hair out for around 4 days over this, I found what appears to be the solution here: 在此期间将头发拉出大约4天后,我发现这里的解决方案是:

No visible cause for "Unexpected token ILLEGAL" 没有可见的原因导致“意外令牌非法”

I need to set sendfile to off: 我需要将sendfile设置为off:

sendfile off;

... in my nginx.conf file on the vm. ...在虚拟机上的我的nginx.conf文件中。 This fixes the issue I was having. 这解决了我遇到的问题。

I faced the same issue and as far as i remember i resolved it by changing the line endings from windows to unix . 我遇到了同样的问题,据我所记得,我通过将行尾从windows更改为unix来解决了这个问题。 So my suggestion is to change the line endings to be unix in your preferred editor. 所以我的建议是在您喜欢的编辑器中将行尾更改为unix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM