I'm talking about this line.
I've created a repo that shows a bug.
Conditions that cause it:
- Package manager that flattens
node_modules structure should be used (npm 3 or yarn).
- Project and some of it's deps should use unconflicting (semver-compatible) versions of
express (in my repo it's webpack-bundle-analyzer)
- 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.
I'm talking about this line.
I've created a repo that shows a bug.
Conditions that cause it:
node_modulesstructure should be used (npm 3oryarn).express(in my repo it'swebpack-bundle-analyzer)ejs 0.8.8andwebpack-bundle-analyzerusesejs ^2.5.2)How to reproduce a bug:
Clone this repo and run
npm i && npm startoryarn && yarn run start(remember to usenpm 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-analyzerexpectsexpressto useejs ^2.5.2from it's deps as view engine with it's new syntax forincludemethod, but instead it loadsejs 0.8.8(project's dep) with oldincludesyntax.Why that happens
After
npm installnode_moduleshas the following flattened structure (condition 1):Note that
webpack-bundle-analyzerdoesn't have it's own copy ofexpressundernode_modulesbecause it's version matches project'sexpressdep (condition 2).When
webpack-bundle-analyzerstarts express app it setsejsas default view engine.This line requires
ejsandnodeloads wrong version of it from<project>/node_modules/ejs(condition 3) becauseexpressis located in<project>/node_modules/express, but it should load it from<project>/node_modules/webpack-bundle-analyzer/node_modules/ejs.