import mime from 'mime';
// import { mime } from 'mime'; // this is also tried

const determineFileType = async (filePath) => {
  const type = mime.getType(filePath);
  if (type) {
    logger.info(`File type is: ${type.mime} and the extension is: ${type.ext}`);
  } else {
    logger.info(`Could not determine the file type for ${filePath}`);
  }
  return type;
};

gives this error:

2024-Feb-18 09:11:29:1129 +0ms ip-172-31-47-89 pid:586768 error: uncaughtException: require() of ES Module /home/ubuntu/my-app/node_modules/mime/dist/src/index.js from /home/ubuntu/my-app/src/utils/decompress.ts not supported.
Instead change the require of index.js in /home/ubuntu/my-app/src/utils/decompress.ts to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ubuntu/my-app/node_modules/mime/dist/src/index.js from /home/ubuntu/my-app/src/utils/decompress.ts not supported.
Instead change the require of index.js in /home/ubuntu/my-app/src/utils/decompress.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (/home/ubuntu/my-app/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/home/ubuntu/my-app/src/utils/decompress.ts:19:32)
    at m._compile (/home/ubuntu/my-app/node_modules/ts-node/dist/index.js:857:29)
(node:586768) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[nodemon] app crashed - waiting for file changes before starting...

I have also tried this code:

import { fileTypeFromFile } from 'file-type';

...
const type = await fileTypeFromFile(filePath);
...

which gives this error:

2024-Feb-18 09:14:12:1412 +0ms ip-172-31-47-89 pid:587367 error: uncaughtException: require() of ES Module /home/ubuntu/my-app/node_modules/file-type/index.js from /home/ubuntu/my-app/src/utils/decompress.ts not supported.
Instead change the require of index.js in /home/ubuntu/my-app/src/utils/decompress.ts to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ubuntu/my-app/node_modules/file-type/index.js from /home/ubuntu/my-app/src/utils/decompress.ts not supported.
Instead change the require of index.js in /home/ubuntu/my-app/src/utils/decompress.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (/home/ubuntu/my-app/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/home/ubuntu/my-app/src/utils/decompress.ts:19:21)
    at m._compile (/home/ubuntu/my-app/node_modules/ts-node/dist/index.js:857:29)
(node:587367) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

really confused here.

What is this error? I am having trouble finding a clue...

0

There are 0 best solutions below