14

I am following this tutorial to build a new tab chrome extension .. https://facebook.github.io/react/docs/tutorial.html

but when I attach

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>

for rendering JSX using babel as suggested by the tutorial I get this error from the browser console.

"browser.min.js:4 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' blob: filesystem: chrome-extension-resource:"." screenshot of the error

I know this is violating CSP directive but then again how can I use the latest reactJS using babel?

1
  • Include browser.min.js as a file in your extension, and link to that. (I feel like this should be a duplicate of another question, but I can't find it.) You can also use "content_security_policy" in your manifest, but that's more complicated. Commented Feb 5, 2016 at 18:32

3 Answers 3

39

In your manifest.json file, you can try setting

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"

I got the answer from here. This got rid of the error for me, but I'm not knowledgeable enough about it to know about other implications, sorry.

Sign up to request clarification or add additional context in comments.

2 Comments

Great.. I was facing similar problem. It's working now with this solution.
I solved this problem using the default "production" mode of webpack.
3

Adding INLINE_RUNTIME_CHUNK=false in my .env file totally fixed it for me.

Comments

2

For anyone coming here, Bruno's answer is more correct. Use the "production" mode. E.g. in Angular

ng build --prod

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.