Skip to content

Error with importing Danger module in Dangerfile.js #1459

Open
@npatmedia

Description

I'm encountering an error when trying to import the Danger module in my Dangerfile.js. Additionally, the provided Spectrum discussion thread link (https://spectrum.chat/?t=0a005b56-31ec-4919-9a28-ced623949d4d) is broken and returns a 404 error.

Error Message:
throw "\nHey there, it looks like you're trying to import the danger module. Turns out\nthat the code you write in a Dangerfile.js is actually a bit of a sneaky hack. \n\nWhen running Danger, the import or require for Danger is removed before the code\nis evaluated. Instead all of the imports are added to the global runtime, so if\nyou are importing Danger to use one of it's functions - you should instead just\nuse the global object for the root DSL elements.\n\nThere is a spectrum thread for discussion here:\n - https://spectrum.chat/?t=0a005b56-31ec-4919-9a28-ced623949d4d\n";
^
Hey there, it looks like you're trying to import the danger module. Turns out
that the code you write in a Dangerfile.js is actually a bit of a sneaky hack.
When running Danger, the import or require for Danger is removed before the code
is evaluated. Instead all of the imports are added to the global runtime, so if
you are importing Danger to use one of it's functions - you should instead just
use the global object for the root DSL elements.
There is a spectrum thread for discussion here:

Steps to Reproduce:

  1. Create a Dangerfile.js with the following content:

`import { danger, markdown, message, warn } from 'danger';

// Example usage of danger
markdown('This is a markdown message');`

  1. Run the Danger.js script using Node.js v20.11.0.
    Expected Behavior:
    The Danger.js script should run without throwing an import error, and the appropriate actions should be executed as specified in the Dangerfile.js.

Actual Behavior:
The script throws an error indicating that importing the Danger module is not allowed. Additionally, the provided link to the Spectrum discussion thread is broken and returns a 404 error.

Environment:

Node.js version: v20.11.0
Danger.js version: [Specify the version you are using]
Additional Context:
The error suggests that the import for Danger is removed before the code is evaluated, and all imports are added to the global runtime instead. However, there is no clear documentation on this behavior, and the broken Spectrum link makes it difficult to find further information or discussion on the topic.

Please provide guidance on how to properly use Danger.js with Node.js v20.11.0 and any updates on the broken Spectrum thread link.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions