赫斯基赋予错误SyntaxError:在严格模式下使用const [英] Husky giving error SyntaxError: Use of const in strict mode

查看:491
本文介绍了赫斯基赋予错误SyntaxError:在严格模式下使用const的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用赫斯基 Lint-staged Stylelint

 scripts:{
precommit:lint-staged,

},
lint-staged:{
* .scss:[stylelint --syntax scss
]
},

操作系统 - 最新的OSX



节点 - 6.10.0



- 3.10.00



git commit

 > ; husky  -  npm run -s precommit 

/Users/jitendravyas/app/node_modules/lint-staged/src/index.js:6
const path = require('path')
^^^^^
SyntaxError:在严格模式下使用const。
at exports.runInThisContext(vm.js:73:16)
at Module._compile(module.js:443:25)
at Object.Module._extensions..js(module。在Module.load(module.js:355:32)
在Function.Module._load(module.js:310:12)
在Module.require
(module.js:365:17)
在require(module.js:384:17)
在Object。< anonymous> (/Users/jitendravyas/app/node_modules/lint-staged/index.js:2:1)
在Module._compile(module.js:460:26)
在Object.Module._extensions。 .js(module.js:478:10)

>哈士奇 - 预先提交挂钩失败(添加 - 无验证绕过)
> husky - 调试,使用'npm run precommit'


解决方案

我正在使用节点 7.10.0 并且有同样的问题。我发现登录其回购站的问题,其中 mmoutenot 发布了一个有趣的回复,让我想到了所以我进一步研究并找到了解决方案!



赫斯基假设每个人都使用 nvm 来管理节点版本并在 NVM_DIR 设置为 $ HOME / .nvm ),或者使用brew BREW_NVM_DIR 设置为 / usr / local / opt / nvm

如果任一路径存在,则使用 load_nvm



当我最初开始使用Node时,确实使用 nvm ,但后来转向使用 n ,但没有意识到 .nvm 在主目录下未被清理,因此它指向的是旧版本节点( 0.12.7 ) - 导致上述错误。



如果您仍在使用nvm来管理节点版本请确保更新到支持ES6功能的节点版本(本例中 const )。



如果您不使用nvm,而是确保 nvm 在上述路径中不可用。赫斯基在这种情况下最终使用当前版本(例如,在您的情况下 6.10.0 尝试 mmoutenot 赫斯基问题


I am using Husky with Lint-staged and Stylelint

  "scripts": {
    "precommit": "lint-staged",

  },
  "lint-staged": {
    "*.scss": ["stylelint --syntax scss"
    ]
  },

OS - Latest OSX

Node - 6.10.0

NPM - 3.10.00

I'm getting this error on git commit

> husky - npm run -s precommit

/Users/jitendravyas/app/node_modules/lint-staged/src/index.js:6
const path = require('path')
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/jitendravyas/app/node_modules/lint-staged/index.js:2:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'

解决方案

I was using node 7.10.0 and had the same problem. I found an issue logged on it's repo where mmoutenot posted an interesting reply which got me thinking so I looked into it further and found the solution!

Husky assumes that everyone uses nvm to manage node versions and looks for it under NVM_DIR(set to $HOME/.nvm) or if installed with brew BREW_NVM_DIR(set to /usr/local/opt/nvm)

if either path exists than it loads the node version using load_nvm.

When I initially started working with Node I did use nvm but later on moved on to using n and didn't realise that .nvm had not been cleaned up under the home directory so it was pointing to an older version of node(0.12.7) - which caused above mentioned error.

If you are still using nvm to manage node versions please ensure that you update to node version that supports ES6 features(const in this case).

If you are not using nvm than ensure that the nvm is not available on above mentioned paths. Husky ends up using the current version in that case (i.e. 6.10.0 in your case)

Alternatively you can try the solution that mmoutenot mentioned on husky issue

这篇关于赫斯基赋予错误SyntaxError:在严格模式下使用const的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆