LoginSignup
2
0

More than 3 years have passed since last update.

Express×pugでアプリをビルドしたら、Cannot find module 'jade'とエラーが出た

Last updated at Posted at 2020-09-26

今回は「Express × pug」環境を構築しようとしたら、エラーが出てハマったので共有します。

こんなエラーが出た

Error: Cannot find module 'jade'
     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
     at Function.Module._load (internal/modules/cjs/loader.js:506:25)
     at Module.require (internal/modules/cjs/loader.js:636:17)
     at require (internal/modules/cjs/helpers.js:20:18)
     at new View (/app/node_modules/express/lib/view.js:81:14)
     at Function.render (/app/node_modules/express/lib/application.js:570:12)
     at ServerResponse.render (/app/node_modules/express/lib/response.js:1008:7)
     at /app/app.js:38:7
     at Layer.handle_error (/app/node_modules/express/lib/router/layer.js:71:5)
     at trim_prefix (/app/node_modules/express/lib/router/index.js:315:13)

jadeというモジュールがないよって言われました。

解決方法

Expressのapp.jsのテンプレート・エンジンの指定をjadepugに変更します。

// app.js
app.set('views', path.join(__dirname, 'views'));
//以下の第二引数を変更します
// app.set('view engine', 'jade');
app.set('view engine', 'pug');

ExpressApp.jsでテンプレート・エンジンを指定できるんですね。
公式ドキュメントはちゃんと読むべきと反省。

Jadeをインストールしたら、ビルドはできるが、新たな警告が表示される

MacBookPro:src home$ npm i jade
npm WARN deprecated jad@0.0.0: Lost intereste in developing that, I've stopped switching OS 2 times a day...
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.

調べてみると、pugjadeの後継のようです。
jadeは古いので、使わない方が良さそうですね。

参考資料

ありがとうございました。
https://stackoverflow.com/questions/47913589/error-cannot-find-module-jade-after-switching-to-pug
https://qiita.com/ganariya/items/85e51e718e56e7d128b8

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0