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

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.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (13 by maintainers)

Commits related to this issue

Most upvoted comments

awesome, ill get a patch that uses that idea shortly

cc @rejas

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

just run: npm install lodash

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

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

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

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 😄