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.

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script

See original GitHub issue

I just installed prettier@1.4 (which supports typescript formatting) in my local project, added .ts onto list of files that prettier should run on, and saved a typescript file. I got the following output:

image

EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".
Hide Stack Trace
EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".
    at Object.parse (/Users/murphy/projects/dayone/DayOne-Web/prj-app/node_modules/prettier/index.js:12058:21)
    at formatWithCursor (/Users/murphy/projects/dayone/DayOne-Web/prj-app/node_modules/prettier/index.js:12267:22)
    at format (/Users/murphy/projects/dayone/DayOne-Web/prj-app/node_modules/prettier/index.js:12307:10)
    at formatWithShebang (/Users/murphy/projects/dayone/DayOne-Web/prj-app/node_modules/prettier/index.js:12465:12)
    at Object.format (/Users/murphy/projects/dayone/DayOne-Web/prj-app/node_modules/prettier/index.js:12481:12)
    at executePrettier (/Users/murphy/.atom/packages/prettier-atom/dist/executePrettier/executePrettierOnBufferRange.js:18:38)
    at executePrettierOrPrettierEslint (/Users/murphy/.atom/packages/prettier-atom/dist/executePrettier/executePrettierOnBufferRange.js:29:70)
    at executePrettierOnBufferRange (/Users/murphy/.atom/packages/prettier-atom/dist/executePrettier/executePrettierOnBufferRange.js:38:21)
    at formatOnSaveIfAppropriate (/Users/murphy/.atom/packages/prettier-atom/dist/formatOnSave/index.js:14:122)
    at lazyFormatOnSave (/Users/murphy/.atom/packages/prettier-atom/dist/main.js:40:15)
    at /Users/murphy/.atom/packages/prettier-atom/dist/main.js:101:14
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1119:26)
    at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:1108:25)
    at TextEditor.module.exports.TextEditor.save (/Applications/Atom Beta.app/Contents/Resources/app/src/text-editor.js:925:32)
    at Pane.module.exports.Pane.saveItem (/Applications/Atom Beta.app/Contents/Resources/app/src/pane.js:780:24)
    at Pane.saveItem (/Applications/Atom Beta.app/Contents/Resources/app/src/pane.js:3:65)
    at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom Beta.app/Contents/Resources/app/src/pane.js:763:25)
    at Workspace.saveActivePaneItem (/Applications/Atom Beta.app/Contents/Resources/app/src/workspace.js:1503:46)
    at atom-workspace.core:save (/Applications/Atom Beta.app/Contents/Resources/app/src/register-default-commands.js:236:38)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom Beta.app/Contents/Resources/app/src/command-registry.js:265:35)
    at /Applications/Atom Beta.app/Contents/Resources/app/src/command-registry.js:3:65
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:610:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:401:28)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom Beta.app/Contents/Resources/app/src/window-event-handler.js:100:42)
    at HTMLDocument.<anonymous> (/Applications/Atom Beta.app/Contents/Resources/app/src/window-event-handler.js:3:65)

Prettier:Debug output:

Atom version: 1.18.0-beta2
prettier-atom version: 0.31.1
prettier version: 1.3.1
prettier-eslint version: 6.2.2
prettier-atom configuration: {
  "formatOnSave": true,
  "formatOnSaveOptions": {
    "enabled": true,
    "scopes": [
      "source.js",
      "source.ts"
    ],
    "showInStatusBar": true,
    "respectEslintignore": true,
    "excludedGlobs": [],
    "whitelistedGlobs": []
  },
  "prettierOptions": {
    "parser": "flow",
    "singleQuote": false,
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "trailingComma": "none"
  },
  "silenceErrors": false,
  "useEslint": false,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:5

github_iconTop GitHub Comments

2reactions
robwisecommented, Jun 2, 2017

Okay 1.4.1 was just released, and I’ve verified that this solves the problem!

2reactions
margiccommented, Jun 2, 2017

Answering my own question dropping prettier to “prettier”: “1.31.1”, works for now with prettier-atom 0.31.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome extension compiled by Webpack throws `unsafe-eval ...
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security ......
Read more >
Refused to evaluate a string as JavaScript because ... - GitHub
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content ...
Read more >
ERROR EvalError: Refused to evaluate a string as JavaScript ...
EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content ...
Read more >
unsafe-eval is not an allowed source of script in the following ...
Refused to evaluate a string as JavaScript because unsafe -eval is not an allowed source of script in the following Content Security Policy...
Read more >
Chrome: script-src eval: Refused to evaluate a string as ...
Solution: Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content ......
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