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

Issue with import and require statement in v3, no problem in v2 #932

Closed
Shawful opened this issue Mar 15, 2023 · 2 comments
Closed

Issue with import and require statement in v3, no problem in v2 #932

Shawful opened this issue Mar 15, 2023 · 2 comments
Labels

Comments

@Shawful
Copy link

Shawful commented Mar 15, 2023

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): no
  • Affecting a production system? (yes/no): no

Context

  • Node.js version: 16.13.1
  • Release Line of Formidable (Legacy, Current, Next): Current
  • Formidable exact version: v3.2.25 --> v2.1.1
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules): nextjs

What are you trying to achieve or the steps to reproduce?

Trying to install formidable without esm errors.

What was the result you got?

Initially, my project was experiencing the following error:

Error: Cannot find module 'formidable'
Require stack:
- /home/ubuntu/lovesRealty/app/middleware.js
- /home/ubuntu/lovesRealty/app/server.js
- /home/ubuntu/lovesRealty/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:81:25)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/ubuntu/lovesRealty/app/middleware.js:8:20)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/ubuntu/lovesRealty/app/middleware.js',
    '/home/ubuntu/lovesRealty/app/server.js',
    '/home/ubuntu/lovesRealty/index.js'
  ]
}

I expected to be able to install formidable using

npm install formidable

and found that the latest version uses an import command in its index.js file, which causes my build to have issues. and errors like:

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ubuntu/project/node_modules/formidable/src/index.js from /home/ubuntu/project/app/middleware.js not supported.
Instead change the require of index.js in /home/ubuntu/project/app/middleware.js to a dynamic import() which is available in all CommonJS modules.
    at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
    at Object.<anonymous> (/home/ubuntu/project/app/middleware.js:8:20)
    at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
    at Object.<anonymous> (/home/ubuntu/project/app/server.js:4:20)
    at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
    at Object.<anonymous> (/home/ubuntu/project/index.js:2:16)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23) {
  code: 'ERR_REQUIRE_ESM'
}

What result did you expect?

I expected it to work as it did with previous versions of formidable.

BIG FYI - I found that when I rolled back to the previous version with :

npm install formidable@v2

that my server wasn't crashing anymore but wanted to let y'all know.

@Shawful Shawful added the bug label Mar 15, 2023
@nicolasheady
Copy link

Experiencing same thing

@GrosSacASac
Copy link
Contributor

The problem is that your entry point is not an ES module.
https://nodejs.org/api/packages.html#determining-module-system

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

No branches or pull requests

3 participants