使用JSHint检测Hello World脚本时出现“Bad option: 'script'”错误求助
Hey there! Let's get that JSHint error sorted out quickly. The problem here is a mix-up between JSHint configuration options and npm scripts—they belong in different places, and JSHint doesn't recognize a script option in its config.
Here's what went wrong:
You added the lint script directly into your JSHint config, but that's not where npm scripts live. JSHint's config should only contain rules/settings related to code linting, not command-line scripts.
Step 1: Fix your JSHint config
Remove the "script" key entirely. Your corrected JSHint config (either in .jshintrc or the relevant section) should look like this:
{ "browser": true, "browserify": true, "devel": true }
Step 2: Move the lint script to package.json
The lint command belongs in the scripts field of your package.json. Update your package.json to include it properly:
{ "name": "myangular", "version": "1.0.0", "scripts": { "lint": "jshint src" }, "devDependencies": { "jshint": "^2.9.5" } }
Why this works:
- JSHint uses its config to know how to analyze your code (like enabling browser-specific globals with
browser: true). - npm uses the
scriptsfield to store reusable commands—now you can runnpm run lintto trigger JSHint on yoursrcfolder, and JSHint won't throw that invalid option error anymore.
Give it a test run, and that error should be gone!
内容的提问来源于stack exchange,提问作者Xiaolin Lan

