Skip to content

View engines require logic can fail under some conditions  #3124

Description

@th0r

I'm talking about this line.

I've created a repo that shows a bug.

Conditions that cause it:

  1. Package manager that flattens node_modules structure should be used (npm 3 or yarn).
  2. Project and some of it's deps should use unconflicting (semver-compatible) versions of express (in my repo it's webpack-bundle-analyzer)
  3. Project (or some of it's deps) and this dep should have incompatible versions of the same template engine (in my repo project uses ejs 0.8.8 and webpack-bundle-analyzer uses ejs ^2.5.2)

How to reproduce a bug:

Clone this repo and run npm i && npm start or yarn && yarn run start (remember to use npm 3).

You'll see an error ENOENT: no such file or directory, open '/Volumes/Work/express-view-engines-bug/node_modules/webpack-bundle-analyzer/views/('style', { filename: 'viewer.css' })'.

This is because webpack-bundle-analyzer expects express to use ejs ^2.5.2 from it's deps as view engine with it's new syntax for include method, but instead it loads ejs 0.8.8 (project's dep) with old include syntax.

Why that happens

After npm install node_modules has the following flattened structure (condition 1):

node_modules
|- express
|- ejs 0.8.8
|- webpack-bundle-analyzer
|- |- node_modules
|- |- |- ejs 2.5.2

Note that webpack-bundle-analyzer doesn't have it's own copy of express under node_modules because it's version matches project's express dep (condition 2).

When webpack-bundle-analyzer starts express app it sets ejs as default view engine.
This line requires ejs and node loads wrong version of it from <project>/node_modules/ejs (condition 3) because express is located in <project>/node_modules/express, but it should load it from <project>/node_modules/webpack-bundle-analyzer/node_modules/ejs.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions