Skip to content

Resolution of this package as ESM is broken due to missing package.json in esm output #269

Closed

Description

NodeJS is resolving this package as CommonJS because a package.json file with "type": "module" is missing from the esm output.
Here is the error I am getting:

SyntaxError: Named export 'LabelFilter' not found. The requested module '@azure/app-configuration-provider' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:

  import pkg from '@azure/app-configuration-provider';
  const { LabelFilter, load } = pkg;

      at ModuleJob._instantiate (node:internal/modules/esm/module_job:220:21)
      at async ModuleJob.run (node:internal/modules/esm/module_job:321:5)
      at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
      at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

  Node.js v22.17.1

If I add a package.json to the dist/esm folder with the contents below, then the error is fixed:

{
  "type": "module"
}

I copied this from the @azure/app-configuration package's esm folder.

Activity

  1. zhiyuanliang-ms commented on Jan 30, 2026

    @zhiyuanliang-ms
    Member

    Hey, Andrew Jaffie (@ajaffie)

    Sorry for the inconvenience.

    I was trying to reproduce the issue. But I cannot reproduce the same error message that you got.

    Could you please share your code and your setup with me to help me reproduce the issue?

    The code below can work on my side.

    import { LabelFilter, load } from '@azure/app-configuration-provider';
    
    const appConfig = await load(connectionString, {
        selectors: [
            {
                keyFilter: "*",
                labelFilter: LabelFilter.Null
            }
        ]
    });
    
    console.log(appConfig.get("Message"));

    This is my package.json and tsconfig.json

    {
      "name": "typescript-playground",
      "version": "1.0.0",
      "type": "module",
      "scripts": {
        "build": "tsc",
        "start": "node dist/index.js"
      },
      "devDependencies": {
        "@types/node": "^25.1.0",
        "typescript": "^5.6.0"
      },
      "dependencies": {
        "@azure/app-configuration-provider": "2.3.1"
      }
    }
    {
      "compilerOptions": {
        "target": "ES2019",
        "module": "nodenext",
        "moduleResolution": "nodenext",
        "outDir": "dist",
        "strict": true,
        "esModuleInterop": true
      },
      "include": ["src"]
    }

    I am using Node.js 22.22.1.


    NodeJS is resolving this package as CommonJS because a package.json file with "type": "module" is missing from the esm output.

    We are use conditional exports (which following Azure SDK's practice)

    So the node.js resolution or bundlers should be able to find the correct entry point.


    But I do find that if I use default export (like the suggestion from the error message you posted)

    import pkg from '@azure/app-configuration-provider';
    const { LabelFilter, load } = pkg;
    
    const appConfig = await load(connectionString, {
        selectors: [
            {
                keyFilter: "*",
                labelFilter: LabelFilter.Null
            }
        ]
    });
    
    console.log(appConfig.get("Message"));

    I will get the following error:

    import pkg from '@azure/app-configuration-provider';
           ^^^
    SyntaxError: The requested module '@azure/app-configuration-provider' does not provide an export named 'default'
        at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21)
        at async ModuleJob.run (node:internal/modules/esm/module_job:335:5)
        at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
        at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
    
    Node.js v22.21.1

    This is because we don't have default export in the esm artifact.

  2. martinnajjar12 commented on Feb 20, 2026

    @martinnajjar12

    I am experiencing the same issue. Locally, if I add "type": "module" to the main package.json` of this package in node_modules, the issue is resolved.
    my tsconfig.json file:

    {
      "extends": "fastify-tsconfig",
      "compilerOptions": {
        "outDir": "dist",
        "rootDir": "src",
        "sourceMap": true,
        "declaration": false,
        "baseUrl": "./",
        "paths": {
          "@/*": ["./src/*"]
        }
      },
      "include": ["src/**/*.ts"],
      "exclude": ["node_modules"]
    }
    

    my package.json file:

    {
      "name": "random name",
      "version": "0.0.0-local",
      "main": "dist/index.js",
      "description": "some description",
      "type": "module",
      "dependencies": {
        "@azure/app-configuration-provider": "2.3.1",
        "@fastify/autoload": "^6.3.1",
        "@fastify/env": "^5.0.3",
        "@fastify/rate-limit": "^10.3.0",
        "@fastify/request-context": "^6.2.1",
        "@fastify/sensible": "^6.0.4",
        "@fastify/swagger": "^9.7.0",
        "@fastify/swagger-ui": "^5.2.5",
        "@fastify/type-provider-typebox": "^6.1.0",
        "@sinclair/typebox": "^0.34.48",
        "async-cache-dedupe": "^3.4.0",
        "close-with-grace": "^2.4.0",
        "fastify": "^5.7.4",
        "fastify-plugin": "^5.1.0",
        "hyperid": "^3.3.0",
        "pino-pretty": "^13.1.3",
        "ioredis": "^5.9.2",
        "undici": "^7.21.0"
      },
      "engines": {
        "node": ">=22.0.0 <23"
      },
    }
    
  3. zhiyuanliang-ms commented on Feb 26, 2026

    @zhiyuanliang-ms
    Member

    Hey, Martin Najjar (@martinnajjar12) Andrew Jaffie (@ajaffie)

    Sorry for the inconvenience. I am looking into this issue.

    Could you please share the code how you import the @azure/app-configuration-provider package to me?

    import { load } from "@azure/app-configuration-provider";
    const appConfig = await load(connectionString);
    console.log(appConfig.get("Message"));

    ESM named import(above) works fine on my side.

    import * as provider from "@azure/app-configuration-provider";
    const appConfig = await provider.load(connectionString);
    console.log(appConfig.get("Message"));

    ESM namespace import(above) works fine.

    import provider from "@azure/app-configuration-provider";
    const appConfig = await provider.load(connectionString);
    console.log(appConfig.get("Message"));

    ESM default import failed with the following error:

    import provider from "@azure/app-configuration-provider";
           ^^^^^^^^
    SyntaxError: The requested module '@azure/app-configuration-provider' does not provide an export named 'default'
        at ModuleJob._instantiate (node:internal/modules/esm/module_job:220:21)
        at async ModuleJob.run (node:internal/modules/esm/module_job:321:5)
        at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
        at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
    const provider = require("@azure/app-configuration-provider");
    (async () => {
      const appConfig = await provider.load(connectionString);
      console.log(appConfig.get("Message"));
    })();
    const { load } = require("@azure/app-configuration-provider");
    (async () => {
      const appConfig = await load(connectionString);
      console.log(appConfig.get("Message"));
    })();

    Both CJS require statements work fine.

    Locally, if I add "type": "module" to the main package.json` of this package in node_modules.

    If we simply add "type": "module" to the package.json of this package. It will break the CJS require usage.

    I need to add "main": "./dist/commonjs/index.js" to specify the entry point for require().

    And I also need to override "type" to "commonjs" in the cjs artifact folder.

  4. zhiyuanliang-ms commented on Feb 26, 2026

    @zhiyuanliang-ms
    Member

    Added "type": "module" to the package.json in PR #280

    Andrew Jaffie (@ajaffie) Martin Najjar (@martinnajjar12)
    Could you verify that this private-built package can work on your side?
    I cannot upload the build to this comment.

  5. martinnajjar12 commented on Apr 28, 2026

    @martinnajjar12

    Hey Zhiyuan Liang (@zhiyuanliang-ms),

    We're still blocked by this, will it be solved? I see the PR you raised is not merged yet.

  6. zhiyuanliang-ms commented on Apr 30, 2026

    @zhiyuanliang-ms
    Member

    Hey, Martin Najjar (@martinnajjar12) Sorry for the late response. I just merged the PR. I was distracted by other tasks and I forgot this issue. We will release it by the first week in May.

    Could you verify that the latest change can solve your problem?

  7. zhiyuanliang-ms commented on Apr 30, 2026

    @zhiyuanliang-ms
    Member

    linglingye001 We need to have a patch release 2.4.2.

  8. zhiyuanliang-ms commented on May 7, 2026

    @zhiyuanliang-ms
    Member
  9. qudwl commented on May 8, 2026

    @qudwl

    Hey! Thank you for finishing up this patch. There were no regressions, just we had an esm only build system which did not work well without this fix.

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions