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

Created on 2 Jun 2017  路  5Comments  路  Source: prettier/prettier-atom

I just installed [email protected] (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
  }
}

bug

Most helpful comment

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

All 5 comments

I'm currently trying to get a hotfix done, but the problem is that 1.4 introduces the use of eval which is against Atom's Content Security Policy (CSP). There is a loophole for this, but it isn't working correctly in this case. I'm still searching for a solution.

Is that 1.4 of prettier itself. Is there a known good version to work with while you work on the fix?

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

Looks like they are going to release a 1.4.1 that will address this, until then, please use margic's solution, the version number is 1.3.1.

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

Was this page helpful?
0 / 5 - 0 ratings