"Cannot use import statement outside a module" - Danger System with React

800 views Asked by At

I am using Danger JS with React app created using create-react-app. So I have a dangerfile.js like below in the Root directory of the project.

import {message, danger} from "danger"

const modifiedMD = danger.git.modified_files.join("- ")
message("Changed Files in this PR: \n - " + modifiedMD)

The import works in this case. But when I am trying to install a plugin like danger-plugin-eslint the import doesn't work.

  import {message, danger} from "danger"
  import eslint from 'danger-plugin-eslint'
  
  const modifiedMD = danger.git.modified_files.join("- ")
  message("Changed Files in this PR: \n - " + modifiedMD)

  eslint()

The error says -

SyntaxError: Cannot use import statement outside a module

I am new to react. Am I missing anything? Any help is appreciated!

1

There are 1 answers

0
Charles Santos On

I faced this error today and as I didn't found the solution anywhere, here one solution that worked for me: just drop the import or requirement lines.

Just this should work fine

const modifiedMD = danger.git.modified_files.join("- ")
message("Changed Files in this PR: \n - " + modifiedMD)