question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token and octokit deprecation error

See original GitHub issue

I’m running a simple example dangerfile.js straight from the docs, using the latest 7.0.2:

import { message, danger } from 'danger';
import { readFileSync } from 'fs';

const modifiedMD = danger.git.modified_files.join('- ');

message(`Changed Files in this PR: \n -  ${modifiedMD}`);

and yarn danger local throws both syntax error and deprecation notice:

> yarn danger local
yarn run v1.13.0
$ <user>/node_modules/.bin/danger local
Error: new Octokit({headers}) is deprecated. Use {userAgent, previews} instead. See https://github.com/octokit/rest.js#client-options
    at parseOptions (<user>/node_modules/@octokit/rest/lib/parse-client-options.js:43:18)
    at new Octokit (<user>/node_modules/@octokit/rest/lib/constructor.js:14:50)
    at apiForDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:114:15)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:72:23)
    at step (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:43:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:24:53)
    at <user>/node_modules/danger/distribution/runner/jsonToDSL.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:14:12)
    at Object.exports.jsonToDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:65:53)

Error: octokit.authenticate() is deprecated. Use "auth" constructor option instead.
    at authenticate (<user>/node_modules/@octokit/rest/plugins/authentication-deprecated/authenticate.js:4:16)
    at apiForDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:116:13)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:72:23)
    at step (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:43:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:24:53)
    at <user>/node_modules/danger/distribution/runner/jsonToDSL.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:14:12)
    at Object.exports.jsonToDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:65:53)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/jsonToContext.js:55:54)

Unable to evaluate the Dangerfile
 dangerfile.js:14
import { readFileSync } from 'fs';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.requireFromString [as default] (<user>/node_modules/require-from-string/index.js:28:4)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/runners/inline.js:144:63)
    at step (<user>/node_modules/danger/distribution/runner/runners/inline.js:32:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/runners/inline.js:13:53)
    at <user>/node_modules/danger/distribution/runner/runners/inline.js:7:71
    at new Promise (<anonymous>)

Error: new Octokit({headers}) is deprecated. Use {userAgent, previews} instead. See https://github.com/octokit/rest.js#client-options
    at parseOptions (<user>/node_modules/@octokit/rest/lib/parse-client-options.js:43:18)
    at new Octokit (<user>/node_modules/@octokit/rest/lib/constructor.js:14:50)
    at apiForDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:114:15)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:72:23)
    at step (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:43:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:24:53)
    at <user>/node_modules/danger/distribution/runner/jsonToDSL.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:14:12)
    at Object.exports.jsonToDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:65:53)
Error: octokit.authenticate() is deprecated. Use "auth" constructor option instead.
    at authenticate (<user>/node_modules/@octokit/rest/plugins/authentication-deprecated/authenticate.js:4:16)
    at apiForDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:116:13)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:72:23)
    at step (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:43:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:24:53)
    at <user>/node_modules/danger/distribution/runner/jsonToDSL.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:14:12)
    at Object.exports.jsonToDSL (<user>/node_modules/danger/distribution/runner/jsonToDSL.js:65:53)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/commands/utils/runDangerSubprocess.js:159:54)
Danger: ⅹ Failing the build, there is 1 fail.
## Failures
Danger failed to run `dangerfile.js`.
## Markdowns
## Error SyntaxError

Unexpected token {
dangerfile.js:14
import { readFileSync } from 'fs';
       ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.requireFromString [as default] (<user>/node_modules/require-from-string/index.js:28:4)
    at Object.<anonymous> (<user>/node_modules/danger/distribution/runner/runners/inline.js:144:63)
    at step (<user>/node_modules/danger/distribution/runner/runners/inline.js:32:23)
    at Object.next (<user>/node_modules/danger/distribution/runner/runners/inline.js:13:53)
    at <user>/node_modules/danger/distribution/runner/runners/inline.js:7:71
    at new Promise (<anonymous>)

### Dangerfile

---------^

Am I missing something?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
maniatorcommented, Feb 14, 2019

It seems after working with @kangax on this that regular node module imports work fine (like ‘lodash’, and ‘danger’), but native imports like fs and path, it seems as though you have to use require('module') and not use import module from 'module' as then you hot the error that @kangax had.

I will try to look into the danger code to see if there is anything I can do for a PR to fix this issue

0reactions
kangaxcommented, Feb 12, 2019

@orta Thanks! The relevant output seems to be:

2019-02-12T18:45:39.679Z danger:inline_runner Handling custom module:  /Users/jzaytsev/dev/spacestation-v2/babel.config.js

2019-02-12T18:45:39.680Z babel:config:loading:files:configuration Auto-ignoring usage of config '/Users/jzaytsev/dev/spacestation-v2/babel.config.js'.

2019-02-12T18:45:39.680Z babel:config:loading:files:configuration Found root config 'babel.config.js' in $o. /Users/jzaytsev/dev/spacestation-v2

2019-02-12T18:45:39.692Z babel:config:loading:files:plugins Loaded plugin '@babel/plugin-transform-flow-strip-types' from '/Users/jzaytsev/dev/spacestation-v2'.

2019-02-12T18:45:39.692Z babel:config:loading:files:configuration Auto-ignoring usage of config '/Users/jzaytsev/dev/spacestation-v2/babel.config.js'.

2019-02-12T18:45:39.692Z babel:config:loading:files:configuration Found root config 'babel.config.js' in $o. /Users/jzaytsev/dev/spacestation-v2

so it finds config but then ignores it?

Full output

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint Parsing error: Unexpected token - Stack Overflow
Unexpected token errors in ESLint parsing occur due to incompatibility between your development environment and ESLint's current parsing ...
Read more >
Build error with @arcgis/core and Angular 11: "Module parse ...
Just chiming in, am getting similar "unexpected token" errors after bumping to v4.24. Had been pinned at v4.22 due to changes to the...
Read more >
How to validate your GraphQL queries with ESLint
To make my queries, I decided to use @octokit/graphql, ... graphql/no-deprecated-fields: error # disallows use of deprecated fields ...
Read more >
unexpected end of json input at json.parse (<anonymous>)
Then more errors, including "Unexpected token d " or similar: Stratum Error SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at ...
Read more >
danger - Bountysource
Unexpected token and octokit deprecation error $ 0. Created 3 years ago in danger/danger-js with 8 comments. I'm running a simple example dangerfile.js ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found