Skip to content

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed #1124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Goodwine opened this issue Nov 7, 2016 · 9 comments

Comments

@Goodwine
Copy link

Goodwine commented Nov 7, 2016

After update 10.1.12 I am getting:

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'".

I reverted the changes from this PR #1117 locally and now things work fine.

@guncha
Copy link
Contributor

guncha commented Nov 7, 2016

You're using a custom typescript version and not the one that came with atom-typescript. If you update to a recent nightly, it should work fine. The current stable (2.0.6?) still has the issue, but you can work around it by creating a wrapper package that's using loophole to require Typescript.

var loophole = require("loophole")
module.exports = loophole.allowUnsafeNewFunction(function() {
  return require("typescript")
})

Then specify a full path to this module.

@dsifford
Copy link

dsifford commented Nov 9, 2016

@guncha I'm getting the issue with typescript 2.1.0-dev.20161109

Edit: No I'm not. Nevermind.

@robey
Copy link

robey commented Dec 12, 2016

I'm still seeing this.

@Goodwine
Copy link
Author

My workaround was doing:

  1. Update makeTypeScriptGlobal.js to:
var loophole = require("loophole");
// ...
global.ts = loophole.allowUnsafeNewFunction(() => require(typescriptPath));
  1. Update package.json to:
"dependencies": {
  // ...
  "loophole": "1.1.0"
}
  1. Install loophole
# Not sure if this is the correct way of doing it as I know nothing about node.
$ cd ~/.atom/packages/atom-typescript/node_modules
$ npm i loophole

@robey
Copy link

robey commented Jan 3, 2017

Is there any legit fix for this in the pipeline? Is atom-typescript deprecated?

@conan747
Copy link

This workaround doesn't work for me... Just to clarify, this is the new makeTypeScriptGlobal.js that I have, in case I made csome mistake:

import {isAbsolute} from "path"

// Debugging helper
global.stack = function() {
    console.error((<any>new Error()).stack);
}

// Export Typescript as a global. Takes an optional full path to typescriptServices.js
export function makeTsGlobal(typescriptPath?: string) {
  if (typescriptPath) {
    if (!isAbsolute(typescriptPath)) {
      throw new Error(`Path to Typescript "${typescriptPath}" is not absolute`)
    }

    typescriptPath = typescriptPath.trim()
  } else {
    typescriptPath = "typescript"
  }
  // I added this:
  var loophole = require("loophole");
  global.ts = loophole.allowUnsafeNewFunction(() => require(typescriptPath));
  // global.ts = require(typescriptPath);
}

@Goodwine
Copy link
Author

@conan747, it seems like you are updating makeTypeScriptGlobal.ts instead of makeTypeScriptGlobal.js

@conan747
Copy link

conan747 commented Feb 1, 2017

Yeah, that was it. Thanks man!

@Goodwine
Copy link
Author

After version 11.x I believe this issue is now fixed.

@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants