I'm developing a chrome extension using webpack and babel.
I have this popup.js:
import 'regenerator-runtime/runtime' // This is required in every JS files that has an async-await function!!
const { NEW_MAPPING_BUTTON } = require('./constants/mapping-page-elements')
const gen_traffic = document.querySelector('.gen-traffic')
gen_traffic.addEventListener('click', async (e) => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: getPageData,
});
})
const getPageData = () => {
console.log('okk?')
console.log( NEW_MAPPING_BUTTON )
}
mapping-page-elements.js:
exports.NEW_MAPPING_BUTTON = () => {
return document.querySelector("app-mappings")
}
webpack.common.js:
const path = require("path");
const ESLintPlugin = require("eslint-webpack-plugin");
module.exports = {
entry: ["regenerator-runtime/runtime.js", "./src/popup.js"],
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
],
noParse: /(mapbox-gl)\.js$/
},
resolve: {
extensions: ["*", ".js"],
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: "bundle.js",
},
devServer: {
static: path.resolve(__dirname, "./dist"),
},
plugins: [new ESLintPlugin()],
};
For some reason, whenever I use the "NEW_MAPPING_BUTTON" in the popup.js file, it gives me "i is not defined" error. I tested the same element that i exported locally in popup.js and it was returning the element just fine, so I believe this is a problem with webpack's exporting system. Thanks in advance.