Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an al... #104

Closed
guncha opened this issue Jul 19, 2016 · 11 comments

Comments

@guncha
Copy link
Contributor

guncha commented Jul 19, 2016

  1. Create an empty project directory
  2. npm init
  3. npm install tslint@next typescript@next --save
  4. Open any Typescript file in the project

Atom Version: 1.8.0
System: Mac OS X 10.11.5
Thrown From: linter-tslint package, v0.10.0

Stack Trace

Uncaught 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 /Users/gunca/Code/tslint-repro/node_modules/typescript/lib/typescript.js:59692

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 Function (native)
    at Object.<anonymous> (/Users/gunca/Code/tslint-repro/node_modules/typescript/lib/typescript.js:59692:23)
    at Module._compile (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/compile-cache.js:208:21)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:50:27)
    at Object.<anonymous> (/Users/gunca/Code/tslint-repro/node_modules/tslint/lib/tslint.js:2:10)
    at Module._compile (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/compile-cache.js:208:21)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:50:27)
    at /Users/gunca/.atom/packages/linter-tslint/lib/init.coffee:62:22
    at /Applications/Atom.app/Contents/Resources/app.asar/node_modules/resolve/lib/async.js:44:21
    at ondir (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/resolve/lib/async.js:187:31)
    at /Applications/Atom.app/Contents/Resources/app.asar/node_modules/resolve/lib/async.js:153:39
    at onex (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/resolve/lib/async.js:93:22)
    at /Applications/Atom.app/Contents/Resources/app.asar/node_modules/resolve/lib/async.js:24:18
    at FSReqWrap.oncomplete (fs.js:82:15)

Commands

Config

{
  "core": {
    "projectHome": "/Users/gunca/Code"
  }
}

Installed Packages

# User
atom-typescript, v10.1.4
atomatigit, v1.5.5
autocomplete-clang, v0.9.4
autocomplete-go, v1.1.0
builder-go, v1.0.0
color-picker, v2.2.2
go-config, v1.2.1
go-get, v1.0.3
go-plus, v4.1.0
gofmt, v1.1.6
gometalinter-linter, v1.1.0
gorename, v1.0.2
hyperclick, v0.0.37
language-diff, v0.4.0
language-graphql, v0.2.0
language-haml, v0.24.0
language-javascript-jsx, v0.3.7
language-llvm, v0.1.1
language-rust, v0.4.6
last-cursor-position, v0.9.0
linter, v1.11.14
linter-rust, v0.4.6
linter-tslint, v0.10.0
navigator-godef, v1.0.3
recent-projects, v0.11.2
tester-go, v1.0.4

# Dev
No dev packages
@gvkhna
Copy link

gvkhna commented Jul 19, 2016

+1

@Arcanemagus
Copy link
Member

Published an update that includes an update of tslint to v3.14.0, please try linter-tslint v0.11.0 and see if you are still having this issue.

@guncha
Copy link
Contributor Author

guncha commented Aug 1, 2016

I'm still seeing the error with 0.11.0 😐 I can help debug if you can point me in the right direction.

@Arcanemagus
Copy link
Member

From this part of the 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 Function (native)
    at Object.<anonymous> (/Users/gunca/Code/tslint-repro/node_modules/typescript/lib/typescript.js:59692:23)

It looks like tslint itself is the problem here, as there were several updates in the meantime you will probably need to grab a new stack trace, then look in the file to figure out how it is trying to use eval (Atom's CSP doesn't allow this).

@dsifford
Copy link

dsifford commented Aug 6, 2016

@Arcanemagus Any updates on this? Have you reached out to @jkillian et al about this if it is indeed an issue with tslint proper?

@jkillian
Copy link

jkillian commented Aug 7, 2016

I'm not aware of any places where we're doing any evaling (in any form) of strings in TSLint. However, if we are, I'm more than happy to change things / accept a PR to fix things, as this is not something we want in our codebase!

@olee
Copy link

olee commented Aug 7, 2016

I found this problem as well trying to use tslint@next / typescript@next for my project and did some debugging.
It looks like it fails when it tries to run require("typescript") inside tslint.js.
I hope this helps.

EDIT: I tried replacing typescript package in .atom/packages/linter-tslint/node_modules with typescript@next and this seems to be enough to get it crashing already.
Looks like loading of the new typescript version seems to be the problem.

@jkillian
Copy link

jkillian commented Aug 8, 2016

Strange, maybe worth filing an issue on TypeScript and seeing if they have any input?

guncha added a commit to guncha/linter-tslint that referenced this issue Aug 8, 2016
@guncha
Copy link
Contributor Author

guncha commented Aug 8, 2016

I've traced to issue to this PR in the Typescript repo (microsoft/TypeScript#9580) that's causing the require("typescript") to break and opened a PR here to address the issue.

@radarsu
Copy link

radarsu commented Oct 23, 2016

I still see the error:

linter-tslint: 0.11.1
typescript: 2.0.3

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.<anonymous> (C:\Users\Artur\Desktop\FTP - dunthag-client\node_modules\typescript\lib\typescript.js:60881:23)
    at Module._compile (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\compile-cache.js:208:21)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\native-compile-cache.js:50:27)
    at Object.<anonymous> (C:\Users\Artur\Desktop\FTP - dunthag-client\node_modules\codelyzer\importDestructuringSpacingRule.js:7:10)
    at Module._compile (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\compile-cache.js:208:21)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (C:\Users\Artur\AppData\Local\atom\app-1.11.2\resources\app.asar\src\native-compile-cache.js:50:27)
    at loadRule (C:\Users\Artur\.atom\packages\linter-tslint\node_modules\tslint\lib\ruleLoader.js:65:26)
    at findRule (C:\Users\Artur\.atom\packages\linter-tslint\node_modules\tslint\lib\ruleLoader.js:46:20)
    at Object.loadRules (C:\Users\Artur\.atom\packages\linter-tslint\node_modules\tslint\lib\ruleLoader.js:14:24)
    at Linter.lint (C:\Users\Artur\.atom\packages\linter-tslint\node_modules\tslint\lib\tslint.js:56:44)
    at file:///C:/Users/Artur/.atom/packages/linter-tslint/lib/init.coffee:103:31

@Arcanemagus
Copy link
Member

@radarsu Please file a new issue with that stack trace. Also in that issue please answer whether tslint works on the CLI for you, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants