Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[commonjs--resolver] node_modules/node-screenshots-darwin-x64/node-screenshots.darwin-x64.node (1:0): Unexpected character '�' (Note that you need plugins to import files that are not JavaScript) #240

Open
ccc469 opened this issue Jun 6, 2024 · 3 comments

Comments

@ccc469
Copy link

ccc469 commented Jun 6, 2024

[commonjs--resolver] node_modules/node-screenshots-darwin-x64/node-screenshots.darwin-x64.node (1:0): Unexpected character '�' (Note that you need plugins to import files that are not JavaScript)

image

"electron": "^30.0.8"

@showonne
Copy link

maybe you should add config follow this: https://github.com/nashaofu/screenshots/blob/master/packages/electron-screenshots/README.md#%E6%B3%A8%E6%84%8F
and if you use vite, you should add config:

optimizeDeps: {
  exclude: ['node-screenshots']
},

@6xiaoxin
Copy link

6xiaoxin commented Feb 8, 2025

[commonjs--resolver] node_modules/node-screenshots-win32-x64-msvc/node-screenshots.win32-x64-msvc.node (1:2): Unexpected character '�' (Note that you need plugins to import files that are not JavaScript)
file: D:/code/electron/node_modules/electron-screenshots/lib/index.js:1:2

1: MZ������ �!�L�!This program cannot be run in DOS mode.
^
2: $���8���k���k���k���j���k���j��k���j���k5�j���k5�j���k5�j���k���j���k���kn��k���k���k�x�j���k�x�j���kRich�...
3: @� �� ��
?

I modified the code according to the method you provided, but this error still persists.

maybe you should add config follow this: https://github.com/nashaofu/screenshots/blob/master/packages/electron-screenshots/README.md#%E6%B3%A8%E6%84%8F and if you use vite, you should add config:

optimizeDeps: {
  exclude: ['node-screenshots']
},

@nashaofu
Copy link
Owner

nashaofu commented Feb 8, 2025

  • If you are using webpack to bundle the main process, modify the following configuration in the main process webpack configuration. Otherwise, issues may occur when invoking the screenshot window.
{
  externals: {
    'electron-screenshots': 'require("electron-screenshots")'
  }
}
// vue.config.js
module.exports = {
  publicPath: ".",
  pluginOptions: {
    electronBuilder: {
      // Do not bundle, use require to load
      externals: ["electron-screenshots"],
    },
  },
};
  • Vite configuration example:
// vite.config.js
import { defineConfig } from "vite";
import viteExternals from "vite-plugin-externals";

export default defineConfig({
  plugins: [
    viteExternals({
      "electron-screenshots": 'require("electron-screenshots")', // Module name: Global variable
    }),
  ],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants