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

Cannot use import statement outside a module #3806

Open
3 tasks done
jorys-paulin opened this issue Jan 17, 2025 · 1 comment
Open
3 tasks done

Cannot use import statement outside a module #3806

jorys-paulin opened this issue Jan 17, 2025 · 1 comment

Comments

@jorys-paulin
Copy link

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

7.6.0

Electron version

v34.0.0

Operating system

Windows 10 (22H2)

Last known working Electron Forge version

Unknown

Expected behavior

After creating a new app using the default template, running npm start should start the app, with no errors thrown

Actual behavior

The application throws the following exception in a dialog and the console:

Cannot use import statement outside a module

Steps to reproduce

  1. Create a new application using npx create-electron-app@latest my-app
  2. Navigate to the new app's folder
  3. Run npm start

Additional information

Node version: v12.13.0 LTS

Screenshot of the error dialog:

Image

Console output when the error is thrown:

(node:13940) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `electron --trace-warnings ...` to show where the warning was created)
App threw an error during load
C:\Users\pauli\Desktop\my-app\src\index.js:1
import { app, BrowserWindow } from 'electron';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1385:20)
    at Module._compile (node:internal/modules/cjs/loader:1435:41)
    at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
    at Module.load (node:internal/modules/cjs/loader:1295:32)
    at Module._load (node:internal/modules/cjs/loader:1111:12)
    at c._load (node:electron/js2c/node_init:2:16955)
    at cjsLoader (node:internal/modules/esm/translators:350:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:286:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
@jorys-paulin
Copy link
Author

It seems like the template was updated to use imports instead of requires in the following commit: f947936.
Changing those back to require fixes the issue. This issue doesn't seem to happen with the Webpack template.

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

No branches or pull requests

2 participants