Modernizr: Error: ENOENT: no such file or directory - lodash

Created on 4 May 2020  ยท  21Comments  ยท  Source: Modernizr/Modernizr

hi all,

working on a next.js project using Modernizr for feature detection. we had installed 3.9.1 and all was working fine with our production builds. however upgrading beyond this version (3.10.0+) has started to create this strange error when we run our build step:

> Build error occurred
Error: ENOENT: no such file or directory, open '/Users/project/node_modules/modernizr/lib/../node_modules/lodash/lodash.js'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
    at Object.readFile (/Users/project/node_modules/requirejs/bin/r.js:3658:27)
    at Object.readFileAsync (/Users/project/node_modules/requirejs/bin/r.js:3672:32)
    at Function.require._cacheReadAsync (/Users/project/node_modules/requirejs/bin/r.js:28102:25)
    at /Users/project/node_modules/requirejs/bin/r.js:27671:48
    at /Users/project/node_modules/requirejs/bin/r.js:3041:37
    at /Users/project/node_modules/requirejs/bin/r.js:2989:25
    at Function.prim.nextTick (/Users/project/node_modules/requirejs/bin/r.js:28083:9)
    at Object.callback (/Users/project/node_modules/requirejs/bin/r.js:2988:26)
    at Object.then (/Users/project/node_modules/requirejs/bin/r.js:3038:23)
    at Object.start (/Users/project/node_modules/requirejs/bin/r.js:3031:34)
    at Object.context.load (/Users/project/node_modules/requirejs/bin/r.js:27655:32)
    at Module.load (/Users/project/node_modules/requirejs/bin/r.js:1084:29)
    at Module.fetch (/Users/project/node_modules/requirejs/bin/r.js:1074:66)
    at Module.check (/Users/project/node_modules/requirejs/bin/r.js:1106:30) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/project/node_modules/modernizr/lib/../node_modules/lodash/lodash.js',
  fileName: '/Users/project/node_modules/modernizr/lib/../node_modules/lodash/lodash.js'
}
error Command failed with exit code 1.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:430:11)
    at Socket.emit (events.js:223:5)
    at Pipe.<anonymous> (net.js:664:12) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'yarn build:next'
}

the next.js build step just compiles our code into server and browser code that runs on the server at runtime. however, this build step seems to throw an error when it gets to the modernizr package.

we've downgraded back to 3.9.1 for now, but we would like to stay up to date. i can't find anything that points to this being a next.js problem, so i'm wondering if anyone else has experienced this, or if it may be more apparent to the maintainers what the issue may be based on what was in the upgrades. i couldn't find anything in particular that stood out to me. here are a few callouts that may be relevant to my use case:

-using a .modernizrrc with this configuration:

module.exports = {
  "options": [
    "addTest",
    "setClasses"
  ],
  "feature-detects": [
    "audio/webaudio",
    "css/flexbox",
    "css/cssgrid",
  ]
}

-using next-plugin-modernizr (which uses webpack-modernizr-loader under the hood).

thanks in advance! pls let me know if i can add any other relevant info.

Most helpful comment

awesome, ill get a patch that uses that idea shortly

cc @rejas

All 21 comments

hi @kaityhallman!
Thanks a lot for the detailed error report!

it looks like the lodash module isn't installed for some reason - can you try deleting the entire node_modules directory, and then reinstall?

hey @patrickkettner thanks for the quick response!
unfortunately that did not change the outcome and i'm still seeing the error.
i have also previously tried adding lodash as a dependency in my own project, without success

would you be able to run the following code within a node repl in the projects folder?

require('lodash')
Object.keys(require.cache)

and post the output?

@patrickkettner for sure!

โžœ  project git:(feature/upgrade) โœ— node
Welcome to Node.js v12.14.1.
Type ".help" for more information.
> require('lodash')
[Function: lodash] {
  templateSettings: {
    escape: /<%-([\s\S]+?)%>/g,
    evaluate: /<%([\s\S]+?)%>/g,
    interpolate: /<%=([\s\S]+?)%>/g,
    variable: '',
    imports: { _: [Circular] }
  },
  after: [Function: after],
  ary: [Function: ary],
  assign: [Function],
  assignIn: [Function],
  assignInWith: [Function],
  assignWith: [Function],
  at: [Function],
  before: [Function: before],
  bind: [Function] { placeholder: [Circular] },
  bindAll: [Function],
  bindKey: [Function] { placeholder: [Circular] },
  castArray: [Function: castArray],
  chain: [Function: chain],
  chunk: [Function: chunk],
  compact: [Function: compact],
  concat: [Function: concat],
  cond: [Function: cond],
  conforms: [Function: conforms],
  constant: [Function: constant],
  countBy: [Function],
  create: [Function: create],
  curry: [Function: curry] { placeholder: [Circular] },
  curryRight: [Function: curryRight] { placeholder: [Circular] },
  debounce: [Function: debounce],
  defaults: [Function],
  defaultsDeep: [Function],
  defer: [Function],
  delay: [Function],
  difference: [Function],
  differenceBy: [Function],
  differenceWith: [Function],
  drop: [Function: drop],
  dropRight: [Function: dropRight],
  dropRightWhile: [Function: dropRightWhile],
  dropWhile: [Function: dropWhile],
  fill: [Function: fill],
  filter: [Function: filter],
  flatMap: [Function: flatMap],
  flatMapDeep: [Function: flatMapDeep],
  flatMapDepth: [Function: flatMapDepth],
  flatten: [Function: flatten],
  flattenDeep: [Function: flattenDeep],
  flattenDepth: [Function: flattenDepth],
  flip: [Function: flip],
  flow: [Function],
  flowRight: [Function],
  fromPairs: [Function: fromPairs],
  functions: [Function: functions],
  functionsIn: [Function: functionsIn],
  groupBy: [Function],
  initial: [Function: initial],
  intersection: [Function],
  intersectionBy: [Function],
  intersectionWith: [Function],
  invert: [Function],
  invertBy: [Function],
  invokeMap: [Function],
  iteratee: [Function: iteratee],
  keyBy: [Function],
  keys: [Function: keys],
  keysIn: [Function: keysIn],
  map: [Function: map],
  mapKeys: [Function: mapKeys],
  mapValues: [Function: mapValues],
  matches: [Function: matches],
  matchesProperty: [Function: matchesProperty],
  memoize: [Function: memoize] { Cache: [Function: MapCache] },
  merge: [Function],
  mergeWith: [Function],
  method: [Function],
  methodOf: [Function],
  mixin: [Function: mixin],
  negate: [Function: negate],
  nthArg: [Function: nthArg],
  omit: [Function],
  omitBy: [Function: omitBy],
  once: [Function: once],
  orderBy: [Function: orderBy],
  over: [Function],
  overArgs: [Function],
  overEvery: [Function],
  overSome: [Function],
  partial: [Function] { placeholder: [Circular] },
  partialRight: [Function] { placeholder: [Circular] },
  partition: [Function],
  pick: [Function],
  pickBy: [Function: pickBy],
  property: [Function: property],
  propertyOf: [Function: propertyOf],
  pull: [Function],
  pullAll: [Function: pullAll],
  pullAllBy: [Function: pullAllBy],
  pullAllWith: [Function: pullAllWith],
  pullAt: [Function],
  range: [Function],
  rangeRight: [Function],
  rearg: [Function],
  reject: [Function: reject],
  remove: [Function: remove],
  rest: [Function: rest],
  reverse: [Function: reverse],
  sampleSize: [Function: sampleSize],
  set: [Function: set],
  setWith: [Function: setWith],
  shuffle: [Function: shuffle],
  slice: [Function: slice],
  sortBy: [Function],
  sortedUniq: [Function: sortedUniq],
  sortedUniqBy: [Function: sortedUniqBy],
  split: [Function: split],
  spread: [Function: spread],
  tail: [Function: tail],
  take: [Function: take],
  takeRight: [Function: takeRight],
  takeRightWhile: [Function: takeRightWhile],
  takeWhile: [Function: takeWhile],
  tap: [Function: tap],
  throttle: [Function: throttle],
  thru: [Function: thru],
  toArray: [Function: toArray],
  toPairs: [Function],
  toPairsIn: [Function],
  toPath: [Function: toPath],
  toPlainObject: [Function: toPlainObject],
  transform: [Function: transform],
  unary: [Function: unary],
  union: [Function],
  unionBy: [Function],
  unionWith: [Function],
  uniq: [Function: uniq],
  uniqBy: [Function: uniqBy],
  uniqWith: [Function: uniqWith],
  unset: [Function: unset],
  unzip: [Function: unzip],
  unzipWith: [Function: unzipWith],
  update: [Function: update],
  updateWith: [Function: updateWith],
  values: [Function: values],
  valuesIn: [Function: valuesIn],
  without: [Function],
  words: [Function: words],
  wrap: [Function: wrap],
  xor: [Function],
  xorBy: [Function],
  xorWith: [Function],
  zip: [Function],
  zipObject: [Function: zipObject],
  zipObjectDeep: [Function: zipObjectDeep],
  zipWith: [Function],
  entries: [Function],
  entriesIn: [Function],
  extend: [Function],
  extendWith: [Function],
  add: [Function],
  attempt: [Function],
  camelCase: [Function],
  capitalize: [Function: capitalize],
  ceil: [Function],
  clamp: [Function: clamp],
  clone: [Function: clone],
  cloneDeep: [Function: cloneDeep],
  cloneDeepWith: [Function: cloneDeepWith],
  cloneWith: [Function: cloneWith],
  conformsTo: [Function: conformsTo],
  deburr: [Function: deburr],
  defaultTo: [Function: defaultTo],
  divide: [Function],
  endsWith: [Function: endsWith],
  eq: [Function: eq],
  escape: [Function: escape],
  escapeRegExp: [Function: escapeRegExp],
  every: [Function: every],
  find: [Function],
  findIndex: [Function: findIndex],
  findKey: [Function: findKey],
  findLast: [Function],
  findLastIndex: [Function: findLastIndex],
  findLastKey: [Function: findLastKey],
  floor: [Function],
  forEach: [Function: forEach],
  forEachRight: [Function: forEachRight],
  forIn: [Function: forIn],
  forInRight: [Function: forInRight],
  forOwn: [Function: forOwn],
  forOwnRight: [Function: forOwnRight],
  get: [Function: get],
  gt: [Function],
  gte: [Function],
  has: [Function: has],
  hasIn: [Function: hasIn],
  head: [Function: head],
  identity: [Function: identity],
  includes: [Function: includes],
  indexOf: [Function: indexOf],
  inRange: [Function: inRange],
  invoke: [Function],
  isArguments: [Function: baseIsArguments],
  isArray: [Function: isArray],
  isArrayBuffer: [Function],
  isArrayLike: [Function: isArrayLike],
  isArrayLikeObject: [Function: isArrayLikeObject],
  isBoolean: [Function: isBoolean],
  isBuffer: [Function: isBuffer],
  isDate: [Function],
  isElement: [Function: isElement],
  isEmpty: [Function: isEmpty],
  isEqual: [Function: isEqual],
  isEqualWith: [Function: isEqualWith],
  isError: [Function: isError],
  isFinite: [Function: isFinite],
  isFunction: [Function: isFunction],
  isInteger: [Function: isInteger],
  isLength: [Function: isLength],
  isMap: [Function],
  isMatch: [Function: isMatch],
  isMatchWith: [Function: isMatchWith],
  isNaN: [Function: isNaN],
  isNative: [Function: isNative],
  isNil: [Function: isNil],
  isNull: [Function: isNull],
  isNumber: [Function: isNumber],
  isObject: [Function: isObject],
  isObjectLike: [Function: isObjectLike],
  isPlainObject: [Function: isPlainObject],
  isRegExp: [Function],
  isSafeInteger: [Function: isSafeInteger],
  isSet: [Function],
  isString: [Function: isString],
  isSymbol: [Function: isSymbol],
  isTypedArray: [Function],
  isUndefined: [Function: isUndefined],
  isWeakMap: [Function: isWeakMap],
  isWeakSet: [Function: isWeakSet],
  join: [Function: join],
  kebabCase: [Function],
  last: [Function: last],
  lastIndexOf: [Function: lastIndexOf],
  lowerCase: [Function],
  lowerFirst: [Function],
  lt: [Function],
  lte: [Function],
  max: [Function: max],
  maxBy: [Function: maxBy],
  mean: [Function: mean],
  meanBy: [Function: meanBy],
  min: [Function: min],
  minBy: [Function: minBy],
  stubArray: [Function: stubArray],
  stubFalse: [Function: stubFalse],
  stubObject: [Function: stubObject],
  stubString: [Function: stubString],
  stubTrue: [Function: stubTrue],
  multiply: [Function],
  nth: [Function: nth],
  noConflict: [Function: noConflict],
  noop: [Function: noop],
  now: [Function],
  pad: [Function: pad],
  padEnd: [Function: padEnd],
  padStart: [Function: padStart],
  parseInt: [Function: parseInt],
  random: [Function: random],
  reduce: [Function: reduce],
  reduceRight: [Function: reduceRight],
  repeat: [Function: repeat],
  replace: [Function: replace],
  result: [Function: result],
  round: [Function],
  runInContext: [Function: runInContext],
  sample: [Function: sample],
  size: [Function: size],
  snakeCase: [Function],
  some: [Function: some],
  sortedIndex: [Function: sortedIndex],
  sortedIndexBy: [Function: sortedIndexBy],
  sortedIndexOf: [Function: sortedIndexOf],
  sortedLastIndex: [Function: sortedLastIndex],
  sortedLastIndexBy: [Function: sortedLastIndexBy],
  sortedLastIndexOf: [Function: sortedLastIndexOf],
  startCase: [Function],
  startsWith: [Function: startsWith],
  subtract: [Function],
  sum: [Function: sum],
  sumBy: [Function: sumBy],
  template: [Function: template],
  times: [Function: times],
  toFinite: [Function: toFinite],
  toInteger: [Function: toInteger],
  toLength: [Function: toLength],
  toLower: [Function: toLower],
  toNumber: [Function: toNumber],
  toSafeInteger: [Function: toSafeInteger],
  toString: [Function: toString],
  toUpper: [Function: toUpper],
  trim: [Function: trim],
  trimEnd: [Function: trimEnd],
  trimStart: [Function: trimStart],
  truncate: [Function: truncate],
  unescape: [Function: unescape],
  uniqueId: [Function: uniqueId],
  upperCase: [Function],
  upperFirst: [Function],
  each: [Function: forEach],
  eachRight: [Function: forEachRight],
  first: [Function: head],
  VERSION: '4.17.15',
  _: [Circular]
}
> Object.keys(require.cache)
[
  '/Users/project/node_modules/lodash/lodash.js'
]

interestingly it looks to be pointing to the main node modules folder in the project itself. when the error points to a dependency within node modules nested in the modernizr dependency in my project... not sure if that is significant

it is! the failure is coming from the requirejs builder, which has a _very_ naive lookup. I submitted a PR to fix this, and it will hopefully be merged and released soon.

Thanks again for such a detailed report! made figuring this out much simpler

nice!! thanks so much for looking into this so quickly @patrickkettner ๐Ÿฅณ

Just released v3.11.1 which hopefully fixes this for you.

hey @rejas, unfortunately i am experiencing a similar, but slightly different error:

> Build error occurred
Error: ENOENT: no such file or directory, open '/Users/project/node_modules/lodash/lodash.js.js'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
    at Object.readFile (/Users/project/node_modules/requirejs/bin/r.js:3658:27)
    at Object.readFileAsync (/Users/project/node_modules/requirejs/bin/r.js:3672:32)
    at Function.require._cacheReadAsync (/Users/project/node_modules/requirejs/bin/r.js:28102:25)
    at /Users/project/node_modules/requirejs/bin/r.js:27671:48
    at /Users/project/node_modules/requirejs/bin/r.js:3041:37
    at /Users/project/node_modules/requirejs/bin/r.js:2989:25
    at Function.prim.nextTick (/Users/project/node_modules/requirejs/bin/r.js:28083:9)
    at Object.callback (/Users/project/node_modules/requirejs/bin/r.js:2988:26)
    at Object.then (/Users/project/node_modules/requirejs/bin/r.js:3038:23)
    at Object.start (/Users/project/node_modules/requirejs/bin/r.js:3031:34)
    at Object.context.load (/Users/project/node_modules/requirejs/bin/r.js:27655:32)
    at Module.load (/Users/project/node_modules/requirejs/bin/r.js:1084:29)
    at Module.fetch (/Users/project/node_modules/requirejs/bin/r.js:1074:66)
    at Module.check (/Users/project/node_modules/requirejs/bin/r.js:1106:30) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/project/node_modules/lodash/lodash.js.js',
  fileName: '/Users/project/node_modules/lodash/lodash.js.js'
}
error Command failed with exit code 1.

Error: Command failed: yarn build:next

this time it's looking for lodash as a dependency within my own project. which makes sense with the change. but there are a few issues with that. first, i didn't initially have lodash as an explicitly installed dependency in my project, so it wouldn't exist per this lookup.

just for the sake of trying, i did install lodash as a dependency, just to see if it would fix the error. however even after installing, the error persisted.
let me know if i can try anything additional to provide more info.

edited: fwiw i did just notice that the error is looking for lodash.js.js which seems suspicious ๐Ÿ˜„

beh. im sorry, require is appending a .js suffix.

Could you try modifying this line

https://github.com/Modernizr/Modernizr/blob/b5ea53df824ede3977c0e710ac23d8525b0210af/lib/build.js#L148

in node_modules/modernizr/lib/build and change it to be this

lodash: require.resolve('lodash').slice(0, -(path.extname(require.resolve('lodash')).length))

@patrickkettner tried this- at first i was getting a reference error from path:
ReferenceError: path is not defined.

however, i added an import for the path module at the top of the file (var path = require('path')), and it built! ๐ŸŽ‰

awesome, ill get a patch that uses that idea shortly

cc @rejas

Shall we unpublish the 3.11.1 version then since it doesnt really fix anything?

Shall we unpublish the 3.11.1 version then since it doesnt really fix anything?

That wouldn't be semantic versioning ๐Ÿ˜•, despite making total sense. I leave it just as a note as it may break systems that work with this model ๐Ÿ™ƒ

Extract:

3, Once a versioned package has been released, the contents of that version MUST NOT be modified. Any modifications MUST be released as a new version.

(I would say that deleting a package is modifying it) (However I would edit the changelog to leave a note or something)

Well, i only meant unpublish it from the npm registry and release a new v3.11.2

nah. it isn't a security issue, no PII is being leaked. it _does_ indicate
we have hole in our tests though.

not that it matters, since lodash and require are out in v4...

On Tue, May 5, 2020 at 3:22 PM Veeck notifications@github.com wrote:

Well, i only meant unpublish it from the npm registry and release a new
v3.11.2

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Modernizr/Modernizr/issues/2556#issuecomment-624255995,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AADRUBVVT54ZIWF26O75PK3RQBRO3ANCNFSM4MZCYBAQ
.

--
patrick

Well, i only meant unpublish it from the npm registry and release a new v3.11.2

@rejas Yeah just though about it in the shower and read it right now, that makes total sense, sorry for the inconvenience. (What Patrick says also makes sense)

hey @patrickkettner just checkin in! how is the progress going on this? we'd like to update soon if possible. thanks :)

hi @kaityhallman patrik provided a new patch which i cannot test at the moment. therefor could you try to change that line 148 again to

    lodash: require.resolve('lodash').replace(/\.[^/.]+$/, ""),

and report back if it fixes that problem of yours?

hey @rejas it works perfectly!

Released v3.11.2 with the (hopefully) final fix. Thx for reporting it.

everything is working great! thank you @rejas, @MarkelFe and @patrickkettner ๐ŸŽ‰

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acschwartz picture acschwartz  ยท  6Comments

chrisbell08 picture chrisbell08  ยท  6Comments

YounesKeraressi picture YounesKeraressi  ยท  8Comments

flying-sheep picture flying-sheep  ยท  6Comments

BenRichter picture BenRichter  ยท  9Comments