tweeeetyのぶろぐ的めも

アウトプットが少なかったダメな自分をアウトプット<br>\(^o^)/

【gulp】gulp@4.0.0にしたら`AssertionError [ERR_ASSERTION]: Task function must be specified`と怒られる

はじめに

とあることで、gulpを3.x.x.から^4.0.0にあげる必要がありました。
f:id:tweeeety:20180618044056p:plain

あげてからgulpタスクを実行すると
以下のようなエラーが出たのでその対応方法をメモ

# defaultタスクを実行するとこんなエラーが...
$ ./node_modules/gulp/bin/gulp.js
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (/Users/tweeeety/gulp-task-gulp4.0.0-sample1/node_modules/undertaker/lib/set-task.js:10:3)
    at Gulp.task (/Users/tweeeety/gulp-task-gulp4.0.0-sample1/node_modules/undertaker/lib/task.js:13:8)
    at Object.<anonymous> (/Users/tweeeety/gulp-task-gulp4.0.0-sample1/gulpfile.js:5:6)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

なぜ起こったか

removed 3 argument syntax for gulp.task  
gulp changelog

github/gulpのchangelogから抜粋ですが、
3.x.xのときのgulp.taskは引数が3つでしたが、
^4.0.0ではgulp.taskの引数が2つになりました。

これによるエラーのようです。

どうすればいいか

gulp.task@3.x.x -> gulp.task@^4.x.x
に書き換える変える一例をあげます。

gulp.task@3.x.x

gulp.task('hoge', 'fuga', function() {
  console.log('callbackの関数');
});

gulp.task@^4.x.x

// 引数は2つに
gulp.task('hoge', gulp.series('fuga', function(callback) {
  console.log('callbackの関数');
  // callback or streamを返さなければならない
  callback();
}));

補足

例はgulp.seriesで書きましたが

直列にしたいか、並列にしたいかで

  • gulp.series
    • 直列にしたいタスクを定義
  • gulp.parallel
    • 並列にしたいタスクを定義

を適宜読み替えてください。

参考サイトを載せておきます。

3.9.1^4.x.xを実際に動かして見比べてみる

そのまま試せる形でgithubに載せてみました。

https://github.com/tweeeety/gulp-task-gulp4.0.0-sample1

  • gulp@3.x.xの書き方
  • gulp@^4.x.xの書き方

をそれぞれ記載しています。

補足

上記のコード例を実行すると
微妙にtaskの呼び出しに変化があります。

Starting 'default'Starting 'task2'あたりの順番が違います。

今回の例でいうと
両者は実質タスク名なだけで中身は何もしてないので影響はないですが
念のため注意が必要そうです。

3.9.1の例
$ ./node_modules/gulp/bin/gulp.js
[00:26:33] Using gulpfile ~/gitrepos/hatena/gulp-task-gulp4.0.0-sample1/gulpfile.js
[00:26:33] Starting 'task1'...
i am task1!!
[00:26:33] Finished 'task1' after 138 μs
[00:26:33] Starting 'task2-1'...
i am task2-1!!
[00:26:33] Finished 'task2-1' after 65 μs
[00:26:33] Starting 'task2-2'...
i am task2-2!!
[00:26:33] Finished 'task2-2' after 82 μs
[00:26:33] Starting 'task2'...
i am task2!!
[00:26:33] Finished 'task2' after 77 μs
[00:26:33] Starting 'task3'...
i am task3!!
[00:26:33] Finished 'task3' after 75 μs
[00:26:33] Starting 'default'...
[00:26:33] Finished 'default' after 19 μs
[~/gitrepos/hatena/gulp-task-gulp4.0.0-sample1 00:26:3
^4.x.xの例
$ ./node_modules/gulp/bin/gulp.js
[00:31:37] Using gulpfile ~/gitrepos/hatena/gulp-task-gulp4.0.0-sample1/gulpfile.js
[00:31:37] Starting 'default'...
[00:31:37] Starting 'task1'...
i am task1!!
[00:31:37] Finished 'task1' after 878 μs
[00:31:37] Starting 'task2'...
[00:31:37] Starting 'task2-1'...
[00:31:37] Starting '<anonymous>'...
i am task2-1!!
[00:31:37] Finished '<anonymous>' after 247 μs
[00:31:37] Finished 'task2-1' after 481 μs
[00:31:37] Starting 'task2-2'...
i am task2-2!!
[00:31:37] Finished 'task2-2' after 240 μs
[00:31:37] Starting '<anonymous>'...
i am task2!!
[00:31:37] Finished '<anonymous>' after 219 μs
[00:31:37] Finished 'task2' after 1.4 ms
[00:31:37] Starting 'task3'...
i am task3!!
[00:31:37] Finished 'task3' after 174 μs
[00:31:37] Finished 'default' after 5.27 ms

こちらも

こちらも合わせてご覧ください

おわり

gulpを3.x.x->4.x.xからあげる場合は
書き直しになる場合が多いかもしれないので要注意
\(^o^)/

【node.js】npm@6にしたらnpm auditでpackageの脆弱性をチェックできるようになったメモ

はじめに

npmコマンドを叩いた際に、@6.x.xにあげてねと言われました。

言われれるがままにあげてみたら
npm auditも行えと言われてなんだこれ..と思って調べた自分用メモです。

f:id:tweeeety:20180615185946j:plain

画像元

アジェンダ

  1. npm auditとは
  2. "npm auditしてね"までの流れ
  3. npm auditの見方と対応の流れ
  4. npm auditの使い方

1. npm auditとは

npm auditは、
npm install/node_modules配下にインストールしたpackageの脆弱性をチェックしてくれるものです。

以下、参考サイトからの引用です。

liftsecurity.ioという企業が持っていた
セキュリティノウハウをnpm側が取得したことにより
packageの脆弱性のチェックができるようになった  

2. "npm auditしてね"までの流れ

npm runスクリプト
# npm runスクリプトを走らせると
# @6.x.xにあげてねと言われる
$ npm run hoge

> hoge@1.0.0 hoge /Users/tweeeety/Hoge
> gulp

[14:52:35] Using gulpfile ~/Hoge/gulpfile.js
(node:9422) [DEP0016] DeprecationWarning: 'root' is deprecated, use 'global'
~ 省略 ~ 
[14:52:35] Finished 'svg' after 119 ms


   ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 5.6.0 → 6.1.0    │
   │     Run npm i -g npm to update      │
   │                                     │
   ╰─────────────────────────────────────╯
素直にあげる
# 一応version確認
$ npm -v
5.6.0

# あげる
$ npm i -g npm
/Users/tweeeety/.nodebrew/node/v8.11.0/bin/npm -> /Users/tweeeety/.nodebrew/node/v8.11.0/lib/node_modules/npm/bin/npm-cli.js
/Users/tweeeety/.nodebrew/node/v8.11.0/bin/npx -> /Users/tweeeety/.nodebrew/node/v8.11.0/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.1.0
added 247 packages, removed 41 packages and updated 129 packages in 15.683s
npm installすると"npm auditしてみ"と言われる
# npmのversionあげたので念のためnpm install
$ npm install
audited 3268 packages in 5.548s
found 6 vulnerabilities (2 low, 4 high)
  run `npm audit fix` to fix them, or `npm audit` for details
  # `npm auditしてね`と言われる

3. npm auditの見方と対応の流れ

npm auditの使い方はいくつかあるようですが、
npm auditとだけうつとチェックと結果のレポートを表示してくれます。

まずは見て見る

$ npm audit

                       === npm audit security report ===

# Run  npm install --save-dev gulp@4.0.0  to resolve 5 vulnerabilities
SEMVER WARNING: Recommended action is a potentially breaking change
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-stream > glob > minimatch             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/118                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-stream > minimatch                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/118                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > glob >     │
│               │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/118                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimatch                                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > minimatch  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/118                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp [dev]                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ gulp > vinyl-fs > glob-watcher > gaze > globule > lodash     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/577                       │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
  2   "name": "hoge",
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.17.5                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ diff-json [dev]                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ diff-json > lodash                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/577                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 6 vulnerabilities (2 low, 4 high) in 3268 scanned packages
  5 vulnerabilities require semver-major dependency updates.
  1 vulnerability requires manual review. See the full report for details.

最初にみるべきは一番下のこれです。

found 6 vulnerabilities (2 low, 4 high) in 3268 scanned packages 5 vulnerabilities require semver-major dependency updates. 1 vulnerability requires manual review. See the full report for details.

6個の脆弱性がみつかって、
2個は低レベル、4つは高レベルの脆弱性だよ、と。

やべーじゃん...

対応してみる

各レポートの上にこんな記載があれば、
それを打つことで解決できそうだよと教えてくれています。

# Run npm install --save-dev gulp@4.0.0 to resolve 5 vulnerabiliti SEMVER WARNING: Recommended action is a potentially breaking change

ということで試して見ます。

# 言われるがままに対応してみる
$ npm install --save-dev gulp@4.0.0
+ gulp@4.0.0
added 97 packages from 80 contributors, removed 29 packages, updated 59 packages and audited 6754 packages in 14.622s
found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details


# 再度脆弱性チェックを行う
# 1つに減っている!
$ npm audit

                       === npm audit security report ===

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.17.5                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ diff-json [dev]                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ diff-json > lodash                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/577                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 low severity vulnerability in 6754 scanned packages
  1 vulnerability requires manual review. See the full report for details.

4. npm auditの使い方

いくつかだけ例をあげます

npm aduit
$ npm audit

# レポートが表示される
npm audit --json

--jsonオプションをつけることで、
レポートをjson形式で表示してくれます。

先ほどの例で--jsonをつけた場合のレポート表示です。

$ npm audit --json
{
  "actions": [
    {
      "action": "install",
      "module": "gulp",
      "target": "4.0.0",
      "isMajor": true,
      "resolves": [
        {
          "id": 118,
          "path": "gulp>vinyl-fs>glob-stream>glob>minimatch",
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "id": 118,
          "path": "gulp>vinyl-fs>glob-stream>minimatch",
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "id": 118,
          "path": "gulp>vinyl-fs>glob-watcher>gaze>globule>glob>minimatch",
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "id": 118,
          "path": "gulp>vinyl-fs>glob-watcher>gaze>globule>minimatch",
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "id": 577,
          "path": "gulp>vinyl-fs>glob-watcher>gaze>globule>lodash",
          "dev": true,
          "optional": false,
          "bundled": false
        }
      ]
    },
    {
      "action": "review",
      "module": "lodash",
      "resolves": [
        {
          "id": 577,
          "path": "diff-json>lodash",
          "dev": true,
          "optional": false,
          "bundled": false
        }
      ]
    }
  ],
  "advisories": {
    "118": {
      "findings": [
        {
          "version": "2.0.10",
          "paths": [
            "gulp>vinyl-fs>glob-stream>glob>minimatch",
            "gulp>vinyl-fs>glob-stream>minimatch"
          ],
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "version": "0.2.14",
          "paths": [
            "gulp>vinyl-fs>glob-watcher>gaze>globule>glob>minimatch",
            "gulp>vinyl-fs>glob-watcher>gaze>globule>minimatch"
          ],
          "dev": true,
          "optional": false,
          "bundled": false
        }
      ],
      "id": 118,
      "created": "2016-05-25T16:37:20.000Z",
      "updated": "2018-03-01T21:58:01.072Z",
      "deleted": null,
      "title": "Regular Expression Denial of Service",
      "found_by": {
        "name": "Nick Starke"
      },
      "reported_by": {
        "name": "Nick Starke"
      },
      "module_name": "minimatch",
      "cves": [
        "CVE-2016-10540"
      ],
      "vulnerable_versions": "<=3.0.1",
      "patched_versions": ">=3.0.2",
      "overview": "Affected versions of `minimatch` are vulnerable to regular expression denial of service attacks when user input is passed into the `pattern` argument of `minimatch(path, pattern)`.\n\n\n## Proof of Concept\n```\nvar minimatch = require(“minimatch”);\n\n// utility function for generating long strings\nvar genstr = function (len, chr) {\n  var result = “”;\n  for (i=0; i<=len; i++) {\n    result = result + chr;\n  }\n  return result;\n}\n\nvar exploit = “[!” + genstr(1000000, “\\\\”) + “A”;\n\n// minimatch exploit.\nconsole.log(“starting minimatch”);\nminimatch(“foo”, exploit);\nconsole.log(“finishing minimatch”);\n```",
      "recommendation": "Update to version 3.0.2 or later.",
      "references": "",
      "access": "public",
      "severity": "high",
      "cwe": "CWE-400",
      "metadata": {
        "module_type": "Multi.Library",
        "exploitability": 4,
        "affected_components": "Internal::Code::Function::minimatch({type:'args', key:0, vector:{type:'string'}})"
      },
      "url": "https://nodesecurity.io/advisories/118"
    },
    "577": {
      "findings": [
        {
          "version": "2.4.2",
          "paths": [
            "diff-json>lodash"
          ],
          "dev": true,
          "optional": false,
          "bundled": false
        },
        {
          "version": "1.0.2",
          "paths": [
            "gulp>vinyl-fs>glob-watcher>gaze>globule>lodash"
          ],
          "dev": true,
          "optional": false,
          "bundled": false
        }
      ],
      "id": 577,
      "created": "2018-04-24T14:27:02.796Z",
      "updated": "2018-04-24T14:27:13.049Z",
      "deleted": null,
      "title": "Prototype Pollution",
      "found_by": {
        "name": "Olivier Arteau (HoLyVieR)"
      },
      "reported_by": {
        "name": "Olivier Arteau (HoLyVieR)"
      },
      "module_name": "lodash",
      "cves": [
        "CVE-2018-3721"
      ],
      "vulnerable_versions": "<4.17.5",
      "patched_versions": ">=4.17.5",
      "overview": "Versions of `lodash` before 4.17.5 are vulnerable to prototype pollution. \n\nThe vulnerable functions are 'defaultsDeep', 'merge', and 'mergeWith' which allow a malicious user to modify the prototype of `Object` via `__proto__` causing the addition or modification of an existing property that will exist on all objects.\n\n",
      "recommendation": "Update to version 4.17.5 or later.",
      "references": "- [HackerOne Report](https://hackerone.com/reports/310443)",
      "access": "public",
      "severity": "low",
      "cwe": "CWE-471",
      "metadata": {
        "module_type": "",
        "exploitability": 1,
        "affected_components": ""
      },
      "url": "https://nodesecurity.io/advisories/577"
    }
  },
  "muted": [],
  "metadata": {
    "vulnerabilities": {
      "info": 0,
      "low": 2,
      "moderate": 0,
      "high": 4,
      "critical": 0
    },
    "dependencies": 0,
    "devDependencies": 3268,
    "optionalDependencies": 196,
    "totalDependencies": 3268
  },
  "runId": "91d63b40-7d49-494e-a020-48ac0af8ffcc"
}
npm audit fix

これはやってみるとわかりますが、
示唆してくれた改善案があればそれを実行してくれるものです。

先ほどの例でいうと
npm audit fix
を打つと
npm install --save-dev gulp@4.0.0
を行なってくれます。

# 例にあげた最初の状態
$ npm audit

~ 省略 ~ 

found 6 vulnerabilities (2 low, 4 high) in 3268 scanned packages
  5 vulnerabilities require semver-major dependency updates.
  1 vulnerability requires manual review. See the full report for details.

# 打って見る
$ npm audit fix
up to date in 2.72s
fixed 0 of 6 vulnerabilities in 3268 scanned packages
  1 vulnerability required manual review and could not be updated
  1 package update for 5 vulns involved breaking changes
  (use `npm audit fix --force` to install breaking changes; or do it by hand)

# 再度チェック
# 結果は1つに減っている
$ npm audit

~ 省略 ~ 

found 1 low severity vulnerability in 6754 scanned packages
  1 vulnerability requires manual review. See the full report for details.
その他

そのほかは公式をご参照あれ。
https://docs.npmjs.com/cli/audit

また、以下の動画でも詳しく解説されていました。
https://www.youtube.com/watch?v=QflNpG3VuGY

おわり

packageの脆弱性のチェックだけじゃなくて
対応コマンドまで表示してくれるのは嬉しいですね!!
\(^o^)/

【Mac】MacBookPro High Sierraで音が出ない、、ボリューム調整できない、内臓スピーカーが認識されない時の対処法

はじめ

MacBookPro High Sierraで急に音が出なくなったので
そのときの自分用メモです。

通常のスピーカーもイヤホンも音が出ませんでした。

症状

この時確認した症状は以下の3点でした

  1. 音が出ない
  2. ボリューム調整ができない
  3. 内蔵スピーカーが認識されていない

1. 音が出ない

これはそのままなのですが、
スピーカー、イヤホン共に音が出ませんでした。

2. ボリューム調整ができない

ボリューム調整をしようとすると以下のような表示になりうんともすんともいいません... f:id:tweeeety:20180614173827p:plain

3. 内蔵スピーカーが認識されていない

アップルアイコン > システム環境設定 > サウンド を開きます。
f:id:tweeeety:20180614173842p:plain

出力タブを開きます。 f:id:tweeeety:20180614173914p:plain

本来はここに何かしら表示されているのですが、
この時はこんな感じで何も表示されていませんでした。
(正常な状態の画像は下の方の直ったあとに貼ってます)

対処

単に再起動するだけで直る場合もあるそうですが自分の場合はだめでした。

行ったのは以下の対応

ハードウェア周りを管理しているSMC (システム管理コントローラ)リセットという方法で直りました。

  1. Macをシステム終了します
  2. キーボードで、「左側のshift + control + option」キーを押しながら、電源ボタンを押します
    • これらのキーと電源ボタンを10秒間押し続けます
    • Touch ID を搭載した MacBook Pro をお使いの場合は、Touch ID ボタンが電源ボタンも兼ねているらしいです
  3. すべてのキーを離します
  4. 再度、電源ボタンを押してMacを起動します

直ったあと

直ったあとは当然音も出ますし、ボリューム調整もできました。

また、アップルアイコン > システム環境設定 > サウンド出力 を見ると正常に表示されました。

通常の状態

f:id:tweeeety:20180614174026p:plain

イヤホンを挿した状態

f:id:tweeeety:20180614174038p:plain

おわり

最初はまぁ音無しでもいいかー
と思って放置してましたがやっぱり音楽聴きたくなりますよねww
\(^o^)/

【make】makefileで`*** missing separator. Stop.`と怒られる

はじめに

すごく初歩的ですが...
make時に以下【make】makefile*** missing separator. Stop.と怒られる

はじめに

すごく初歩的ですが...
make時に以下のようなエラーが出ることがあって小一時間悩んだので自分用いましメモ

$ make
makefile:4: *** missing separator.  Stop.

なぜエラーか

makefileは以下のように記載しますが、

target: file
  command...

commandの前は
スペースではなく、かならずタブ で書く必要があります。

これをスペースで書いてしまったときにタイトルのようなエラーが出ます。

サンプル

  • makefile
    • hoge:の次の行の先頭はタブ
    • fuga:の次の行の先頭がスペース
$ cat makefile
hoge:
    @echo "say hoge"
fuga:
    echo "say fuga"
  • 実行
$ make
makefile:4: *** missing separator.  Stop.

捕捉

vimなどでちゃんとcolor schemeが効いて入ればすぐ気づけます

参考

おわり

これだけの行数サンプルだと即気づくんですが、
結構長いmakefileでcolor scheme無しで書いてたので 一部だけスペースなことに全然気づきませんでした... のようなエラーが出ることがあって小一時間悩んだので自分用いましメモ

$ make
makefile:4: *** missing separator.  Stop.

なぜエラーか

makefileは以下のように記載しますが、

target: file
  command...

commandの前は
スペースではなく、かならずタブ で書く必要があります。

サンプル

  • makefile
    • hoge:の次の行の先頭はタブ
    • fuga:の次の行の先頭がスペース
$ cat makefile
hoge:
    @echo "say hoge"
fuga:
    echo "say fuga"
  • 実行
$ make
makefile:4: *** missing separator.  Stop.

捕捉

vimなどでちゃんとcolor schemeが効いて入ればすぐ気づけます

f:id:tweeeety:20180608211325p:plain

参考

おわり

結構長いmakefileでcolor scheme無しで書いてたので
一部だけスペースなことに全然気づきませんでした...つらみ...\(^o^)/

【node.js】npmで`TypeError: require.extensions.hasOwnProperty is not a function`というエラーで怒られる

はじめに

f:id:tweeeety:20180608202233p:plain

タイトルのまんまですが、 とあるプロジェクトでnpm runスクリプトを走らせると以下のようなエラーが出たのでその対処方メモ

# nodeのversionをあげる
$ nodebrew install v8.11.0
$ nodebrew use v8.11.0

# 念のため削除
$ rm -rf node_modules
$ rm -rf ~/.npm

# いれなおす
$ npm install

# versionをあげる前は動いていたが
# npmスクリプトでエラー
$ npm run sample

> hoge@1.0.0 sample /Users/tweeeety/hoge
> gulp

/Users/tweeeety/hoge/node_modules/require-dir/index.js:97
            if (!require.extensions.hasOwnProperty(ext)) {
                                    ^

TypeError: require.extensions.hasOwnProperty is not a function
    at requireDir (/Users/tweeeety/hoge/node_modules/require-dir/index.js:97:37)
    at Object.<anonymous> (/Users/tweeeety/hoge/gulpfile.js:2:1)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at Liftoff.handleArguments (/Users/tweeeety/hoge/node_modules/gulp/bin/gulp.js:116:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hoge@1.0.0 compile: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hoge@1.0.0 compile 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!     /Users/tweeeety/.npm/_logs/2018-06-08T04_01_16_000Z-debug.log

このときの環境

$ ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17]

$ node -v
v8.11.0

$ npm -v
3.8.6

$ rbenv -v
rbenv 1.1.1

$ nodebrew list
v5.12.0
v8.11.0

current: v8.11.0

なにがおこったか

根本原因

githubのissueにあがってました

https://github.com/tjunnone/npm-check-updates/issues/363

nodeのmoduleのrequire-dirを古いまま使い続けているからぽいです。

自分のところの原因

nodeを8.x.xなどの新しいものにあげましたが、
package.jsonでバージョンを固定したモジュールが古いままだったためでした。

  • nodeを8.x.xにあげた
  • 固定していたmodule(今回でいうrequire-dir)のversionが古いままで8.x.xに対応していないversionのままだった

というかんじ

確認する

まずは今のrequire-dirのversionを確認してみました。
https://github.com/aseemk/requireDir/releases

たしかに0.3.2 -> 1.0.0とあがってます。

f:id:tweeeety:20180608202312p:plain

次に、このプロジェクトで使っているsouce-mapを確認してみます。

# 0.3.0でした
# それが悪いってことでもないけど...
$ npm list require-dir
hoge@1.0.0 /Users/tweeeety/hoge
└── require-dir@0.3.0

対応

では、どうやってバージョンをあげたかというと
今回はncu(npm-check-updates)require-dir以外も一括更新しました。

ncuに関しては以下をご参照ください。

doing!

# nodeのversionをあげる
$ nodebrew install v8.11.0
$ nodebrew use v8.11.0

# 念のため削除
$ rm -rf node_modules
$ rm -rf ~/.npm

# 入ってなければいれる
$ npm uninstall npm-check-updates -g && npm install npm-check-updates -g

# 更新実行
$ ncu
$ ncu -u

# いれなおす
$ npm install

# エラーなくなった!
$ npm run sample

参考

以下のサイトも参考にさせていただきました!thx!

おわり

すぐわかればイイですがこういう系ってハマると長いですよね\(^o^)/

【node.js】ncu(npm-check-updates)でpackage.jsonのmodulesバージョンを一括で更新

はじめに

npm-check-updates、いまさら感はありますが
使ってあらためて便利だったのでこの機会にメモ

f:id:tweeeety:20180608193224p:plain

ncu(npm-check-updates)とは

公式URL

上記の公式からの引用です

npm-check-updates allows you to upgrade your package.json dependencies to the latest versions, regardless of existing version constraints.

package.jsonの依存関係を最新のバージョンにアップグレードしてくれるmoduleですね。

インストール

グローバルにインストールして使います

$ npm install -g npm-check-updates

使い方

dry-run

ncuと打つと実際には更新せずに、
更新対象のリストが表示されます。

$ ncu
 $ ncu
Using /Users/tweeeety/hoge/package.json
⸨░░░░░░░░░░░░░░░░░░⸩ ⠴ :
 browserify      13.0.1  →  16.2.2
 del              2.2.1  →   3.0.0
 diff-json        0.1.1  →  0.1.11
 es6-promise      4.0.5  →   4.2.4
 gulp-cheerio     0.6.2  →   0.6.3
 gulp-concat      2.6.0  →   2.6.1
 gulp-cssmin      0.1.7  →   0.2.0
 gulp-frontnote   1.0.3  →   2.0.1
 gulp-plumber     1.1.0  →   1.2.0
 gulp-rename      1.2.2  →   1.2.3
 gulp-replace     0.5.4  →   1.0.0
 gulp-svgmin      1.2.2  →   1.2.4
 gulp-svgstore    6.0.0  →   6.1.1
 gulp-uglify      1.5.4  →   3.0.0
 moment          2.14.1  →  2.22.2
 remodal          1.1.0  →   1.1.1
 require-dir      0.3.0  →   1.0.0
 run-sequence     1.2.2  →   2.2.1
 stripify         4.0.0  →   6.0.0
 svg4everybody    2.1.4  →   2.1.9
 through2         2.0.1  →   2.0.3
 underscore       1.8.3  →   1.9.1

Run ncu with -u to upgrade package.json

更新

ncu -uとすることで
実際に更新が走り、合わせてpackage.jsonも書き換えてくれます。

$ ncu -u

あとは公式に詳しく書いてあるので以上、、、ということで、、、w
https://github.com/tjunnone/npm-check-updates#options

おわり

全体的にサクっとupdateできるので便利です
\(^o^)/

【node.js】npmで`SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode` というエラーで怒られる

はじめに

f:id:tweeeety:20180608202233p:plain

タイトルのまんまですが、
とあるプロジェクトでnpm runスクリプトを走らせると以下のようなエラーが出たのでその対処方メモ

$ npm run sample

> hoge@1.0.0 sample /Users/tweeeety/hoge
> gulp

/Users/tweeeety/hoge/node_modules/riot-compiler/node_modules/source-map/lib/source-map-generator.js:21
class SourceMapGenerator {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/tweeeety/hoge/node_modules/riot-compiler/node_modules/source-map/source-map.js:6:30)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

npm ERR! Darwin 17.5.0
npm ERR! argv "/Users/tweeeety/.nodebrew/node/v5.12.0/bin/node" "/Users/tweeeety/.nodebrew/current/bin/npm" "run" "compile"
npm ERR! node v5.12.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! hoge@1.0.0 compile: `gulp`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hoge@1.0.0 compile script 'gulp'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the hoge package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gulp
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs hoge
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls hoge
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/tweeeety/hoge/npm-debug.log

このときの環境

$ ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17]

$ node -v
v5.12.0

$ npm -v
3.8.6

$ rbenv -v
rbenv 1.1.1

$ nodebrew list
v5.12.0

current: v5.12.0

なにがおこったか

根本原因

githubのissueにあがってました

Version 0.7.0 of source-map fails to load on Node < 6 due to let without 'use strict'. This causes the following error:

node moduleのsource-map 0.7.0は
'use strict'を使用しないのでnodeのversion<6(6未満)にはロードできないらしい。
そのせいでエラーが発生するとのこと。

自分のところの原因

nodeが5.x.xでも、package.jsonでバージョンをがちがちに固定していれば大丈夫だと思います。

  • nodeが5.x.x
  • 固定していないmodule(今回でいうsource-map)のversionがあがって5.x.xでは動かなくなった

というかんじ

確認する

このプロジェクトで使っているsouce-mapを確認してみます。

# たしかに0.7.3がいる
$ npm list source-map
hoge@1.0.0 /Users/tweeeety/hoge
├─┬ gulp-concat@2.6.1
│ └─┬ concat-with-sourcemaps@1.1.0
│   └── source-map@0.6.1
├─┬ gulp-cssmin@0.2.0
│ └─┬ clean-css@3.4.28
│   └── source-map@0.4.4
├─┬ gulp-uglify@3.0.0
│ ├─┬ uglify-js@3.4.0
│ │ └── source-map@0.6.1
│ └─┬ vinyl-sourcemaps-apply@0.2.1
│   └── source-map@0.5.7
└─┬ riot@3.10.1
  └─┬ riot-compiler@3.5.1
    └── source-map@0.7.3

対応

記載の通りですが、
6以上にあげるとエラーはでなくなりました。

# インストールできるversionを確認
$ nodebrew ls-remote

# とりあえず少しだけあげて6.x.xにする
$ nodebrew install v6.14.2
$ nodebrew use v6.14.2
use v6.14.2

# エラーでない
$ npm run sample

ちなみに

5.x.xもものすっごく昔というわけではないですが、
nodeの5.x.xはサポートは終了しているようです。

特に理由がなさそうならあげちゃったほうがよさそうです。

おわり

5系は古い \(^o^)/