PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 15, 2022

[FIXED] How to import react in background.js of chrome extension

 October 15, 2022     dom, google-chrome-extension, javascript, react-dom, reactjs     No comments   

Issue

I want to use reactDOM for injecting content to page. So, I want to

import React from 'react';
...
import App from './src/js/App';

const root=createRoot(document.getElementById('title'));
root.render(
   <App/>
);

included into my background.js but I get the following error: SyntaxError: Cannot use import statement outside a module

Import that is causing the error:

import React from 'react'

I've done some research and tried adding type: "module" but that does not work.

What can I do to solve this?


Solution

After many research,

I did npm run eject

here is the working react setup

https://github.com/rba1aji/chrome-extension-template-react



Answered By - Balaji
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing