0

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!

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
Rafayet Monon
  • 1,019
  • 8
  • 16
  • Does this answer your question? ["Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6](https://stackoverflow.com/questions/58211880/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-import) – Joe Lloyd Aug 16 '20 at 09:16
  • does this answer your question https://stackoverflow.com/a/58212338/2504407 – Joe Lloyd Aug 16 '20 at 09:16
  • unfortunately, it doesn't. – Rafayet Monon Aug 16 '20 at 09:25
  • Are you using babel and how you created the project? The problem is that your project is not identifying the import keyword this could be a babel problem. – moshfiqrony Aug 16 '20 at 12:00
  • @Md.MoshfiqurRahmanRony React app created using create-react-app. And the dangerfile.js is in the project root. – Rafayet Monon Aug 16 '20 at 12:18
  • So my guess is babel is missing to parse your danger.js. Try using raw JS like require instead of import. – moshfiqrony Aug 17 '20 at 03:21

1 Answers1

0

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)
Charles Santos
  • 739
  • 9
  • 12