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

[ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" #643

Open
abhinavsingh opened this issue Jul 26, 2022 · 1 comment
Open

[ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" #643

abhinavsingh opened this issue Jul 26, 2022 · 1 comment

Comments

@abhinavsingh
Copy link

abhinavsingh commented Jul 26, 2022

This is how I led to conclusion that above error is related to fetch-mock.

  1. I recently got a new laptop. Default node installed by brew is v18.6.0, compared to previous v17.x on my older system
  2. Upgrading node resulted in some caveats e.g. usage of NODE_OPTIONS=--no-experimental-fetch became necessary for rpm run build in some of our repos.
  3. Coming to tests, we observed below stack trace in some of our repos
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/abhinavsingh/Dev/....redacted..../tests/payments.ts
    at new NodeError (node:internal/errors:387:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:80:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:122:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:173:28)
    at ESMLoader.load (node:internal/modules/esm/loader:616:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:472:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:491:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:449:34)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async formattedImport (/Users/abhinavsingh/Dev/....redacted..../node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
  1. Going into payments.ts, as soon as we comment out const fetchMock = require('fetch-mock');, error goes away. We saw similar behaviour for all our tests using fetch-mock
  2. I went to https://www.npmjs.com/package/fetch-mock in hope of a newer version, but found none.
  3. I tried NODE_OPTIONS=--no-experimental-fetch with npm test, but run into same exception.

Dependency list:

    "@types/chai": "^4.3.0",
    "@types/mocha": "^9.1.0",
    "@types/node-fetch": "^2.6.2",
    "chai": "^4.3.6",
    "fetch-mock": "^9.11.0",
    "gulp": "^4.0.2",
    "gulp-typescript": "^6.0.0-alpha.1",
    "jsdom": "^20.0.0",
    "jsdom-global": "^3.0.2",
    "mocha": "^10.0.0",
    "node-fetch": "^3.2.9",
    "nyc": "^15.1.0",
    "ts-node": "^10.9.1",
    "typedoc": "^0.23.9"

Any help and/or pointers are appreciated. Best

@agustin-del-pino
Copy link

agustin-del-pino commented Jul 26, 2022

Hello, same error from here.

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /workspaces/test/a.super.good.test.ts
    at new NodeError (node:internal/errors:371:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:87:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:102:38)
    at defaultLoad (node:internal/modules/esm/load:21:14)
    at ESMLoader.load (node:internal/modules/esm/loader:359:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async formattedImport (/workspaces/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async Object.exports.requireOrImport (/workspaces/node_modules/mocha/lib/nodejs/esm-utils.js:38:28)
    at async Object.exports.loadFilesAsync (/workspaces/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
    at async singleRun (/workspaces/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/workspaces/node_modules/mocha/lib/cli/run.js:370:5)
{
  "scripts": {
    "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha -r ts-node/register 'tests/**/*.ts'"
  },
  "devDependencies": {
    "@types/chai": "^4.3.1",
    "@types/fetch-mock": "^7.3.5",
    "@types/mocha": "^9.1.1",
    "chai": "^4.3.6",
    "chai-fetch-mock": "^3.0.0",
    "mocha": "^10.0.0",
    "node-fetch": "^3.2.9",
    "ts-node": "^10.9.1",
    "typescript": "^4.7.4"
  }
}

The exception never occurs when the line fetchMock.mock(...); is commented.

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

2 participants