简体   繁体   中英

Can't import a script into another script

I want to share a script between other script. But I can't import it in those scripts. If I use

const { lists } = require("../assets/listManager.js");

it gives me

SyntaxError: Unexpected token export and when I try

import{ lists } from "../assets/listManager.js";

I get

SyntaxError: Unexpected token {

How do I use listManager.js in other scripts?

I'm guessing the script that's doing the importing doesn't have node integration enabled and is running in a renderer process. If you want node integration, you'd need to enable it in the window that hosts that script new BrowserWindow({ webPreferences: { nodeIntegration: true }) .

Otherwise, you can't import thing into the script, You'll have to use a preload script to expose the APIs that you care about to your script, preferably with contextIsolation enabled. See here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM