0

I'm creating a Chrome extension with React using CRA.

I have some scripts that I need to run on specific pages. If I put them in the /src folder, they are not found when I run the extension because of the npm run build command.

For version 3 of the manifest.json file, the background.js, profileEnhancer.js, etc. must be in the same folder as the manifest.json file, or they will not be found.

Any suggestions on how to move manifest.json and background.js into the /src folder and still have it build properly with npm run build, or a way use import in the public folder?

Current Folder Structure: enter image description here

i am trying to import:

import XLSX from 'xlsx';

In the script profileEnhancer.js, but it gives the error:

Uncaught SyntaxError: Cannot use import statement outside a module

If I place all the scripts in the src folder and then build the project to run the extension, the script is not found when it is called due to a localization change. I attempted to rename the scripts to .mjs and added the "type: module" attribute, but it resulted in an error.

chrome.scripting.executeScript({
target: { tabId: details.tabId },
files: ["./js/profileEnhancer.js"],
module: true

I also tried using Babel to create a transpiled version of the script called "profileEnhancer-transpiled.js," but it didn't work. I didn't fully understand how to use it.

0 Answers0