danger-js
danger-js copied to clipboard
[BUG] Cannot import an NPM module
Describe the bug
I'm attempting to use the EventSource NPM module within Danger.js CI module. It's failing with MODULE_NOT_FOUND:
Unable to evaluate the Dangerfile
{ Error: Cannot find module 'eventsource'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function._module2.default._load (/home/jenkins/infra/ci-script-library/danger-js/0.0.15/node_modules/override-require/dist/overrideRequire.js:43:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/var/lib/jenkins/workspace/android-pr-statuschecks_PR-12724/dangerfile.ts:12:19)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.requireFromString [as default] (/home/jenkins/infra/ci-script-library/danger-js/0.0.15/node_modules/require-from-string/index.js:28:4)
at Object.<anonymous> (/home/jenkins/infra/ci-script-library/danger-js/0.0.15/node_modules/danger/distribution/runner/runners/inline.js:144:63)
at step (/home/jenkins/infra/ci-script-library/danger-js/0.0.15/node_modules/danger/distribution/runner/runners/inline.js:32:23) code: 'MODULE_NOT_FOUND' }
Here's a minimal sample. Note that it works fine with yarn danger local:
import {danger, fail, message, warn} from 'danger';
import * as EventSource from 'eventsource';
let test = new EventSource('https://google.com');
To Reproduce Steps to reproduce the behavior:
- This is reproducible in our CI environment. I confirmed that both
EventSourcemodule and@types/EventSourceas well asTypeScriptare installed.
Expected behavior
EventSource is found and executed.
Screenshots If applicable, add screenshots to help explain your problem.
Your Environment
- Jenkins with Github Enterprise.
- Danger runs just fine if I remove the 3rd line (
new EventSource..) above.
| software | version |
|---|---|
| danger.js | v1.22.4 |
| node | v10.15.0 |
| npm | 6.4.1 |
| Operating System | Linux 3.10.0 |
Unsure, there shouldn't be anything unique to how danger handles file resolving
- is it possible you're running on a really old version?
danger-js/0.0.15/? - are node modules definitely installed?
@orta
danger-js/0.0.15/is our internal versioning system, otherwise we're using latest danger.- I can see the module installed in the filesystem.
Same thing happens to me in my gitlab pipeline. It works perfectly well when running local using npx danger pr but not in my pipelines using npx danger ci -f.
I was able to solve it by running the command in my pipeline inside a node:16 docker image.
I have the same problem. Does anyone have any views on this solution?
Closing this as it’s an issue on Node 10, filed in 2020. It’s unlikely to have any further progress or ease of debugging.
Feel free to file a new ticket if it still happens!