Strange behavior with TypeScript, node and “The requested module xxx does not provide an export named yyy”

I’m coming back to Node and TypeScript after being away for a few years, and trying to get back up to speed by building a basic CRUD REST server using Node, Express, Mongoose and TypeScript. I’ve come across a strange error that I can’t quite figure out. A lot has changed since I was last in the weeds on stuff like this (e.g. CommonJS vs ES modules, numerous version revisions of each component, etc.) so I’ve got a lot of balls in the air.

I have code that works fine for a while, and then after touching something random, it will stop working and give me:

SyntaxError: The requested module ‘../utils/LoggerClass’ does not provide an export named ‘LoggerClass’

(or the same error on any number of other classes/files I have that analogous)

…even though the LoggerClass file clearly does export something named LoggerClass (because it just worked). WebStorm does not show these errors in the editor. And if I delete all the .js files in my source tree (e.g. find ... | xargs rm) and run it again, it will make the error go away for a while. Some file edits will not recreate the problem, but than at some point I will make a change that will bring the problem back, requiring me to clear out all the .js files again.

My package.json includes:

  "scripts": {
    "start": "node src/server.ts"
  },
  "type": "module",
  "module": "esnext",

I know there have been some changes in the past few years regarding CommonJS vs ES modules, and I can’t say I understand everything about them, but I seem to be coding using ES modules and using import instead of require, and, like I said earlier, it usually works fine.

I am running node v22.6.0, tsc v5.5.4 and building/running in WebStorm 2024.2 on MacOS.

In terms of WebStorm configurations:

  1. My TypeScript settings include node 22.6.0 as the interpreter, bundled TypeScript (5.4.3), with TypeScript language service, show project errors and show suggestions enabled (but use types from server and “Recompile on changes” off).

  2. My node.js settings include node 22.6.0.

  3. In my project Run Configuration, I have node 22.6.0, TypeScript loader is Bundled (tsx), and node parameters --require ts-node/register

As an example, my LoggerClass.ts file starts with:

import { ILogger } from "../commonCode/misc/ILogger";

export class LoggerClass implements ILogger {
    public traceOn = true;
    constructor(public moduleName: string, public debugMode: boolean) { }

and my references to it look like:

import { LoggerClass } from "../utils/LoggerClass";

For what it’s worth, when WebStorm runs my app, here is the command line it uses:

/Users/USERNAME/.nvm/versions/node/v22.6.0/bin/node
  --import file:/Applications/WebStorm.app/Contents/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/loader.cjs
  --require ts-node/register
  /Users/USERNAME/WebstormProjects/APP-NAME/src/server.ts

And my tsconfig.json looks like (with loads of commented out lines elided for readablity):

{
  "compilerOptions": {

    /* Projects */
    // …

    /* Language and Environment */
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    // …

    /* Modules */
    "module": "commonjs",                                /* Specify what module code is generated. */
    // …

    /* JavaScript Support */
    // …

    /* Emit */
    // …

    /* Interop Constraints */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    // …

    /* Type Checking */
    "strict": true,                                      /* Enable all strict type-checking options. */
    //…

    /* Completeness */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
    // …
  }
}


Any idea what could be causing this problem?

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật