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

npm throws on subpath exports mapping #15605

Closed
mpodwysocki opened this issue Aug 25, 2022 · 5 comments · Fixed by #15652
Closed

npm throws on subpath exports mapping #15605

mpodwysocki opened this issue Aug 25, 2022 · 5 comments · Fixed by #15652
Labels
bug Something isn't working correctly node compat

Comments

@mpodwysocki
Copy link

Using the Azure Notification Hubs SDK for JavaScript, trying to import from a subpath exports causes an error which it doesn't think is exported.

import * as process from "https://deno.land/[email protected]/node/process.ts";
import { SendOperationOptions } from "npm:@azure/[email protected]/models/options";
import { createClientContext } from "npm:@azure/[email protected]/client";
import { createAppleNotification } from "npm:@azure/[email protected]/models/notification";
import { sendDirectNotification } from "npm:@azure/[email protected]/client/sendDirectNotification";

Full code snippet here: Azure Notification Hubs Send Example

Getting the following error:

error: Could not resolve '@azure/notification-hubs@=1.0.0-beta.2/models/notification'.

Caused by:
    0: Error resolving package config for '@azure/notification-hubs@=1.0.0-beta.2/models/notification'.
    1: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './models/notification' is not defined by "exports" in /Users/<redacted>/Library/Caches/deno/npm/registry.npmjs.org/@azure/notification-hubs/1.0.0-beta.2/package.json imported from /Users/<redacted>/Library/Caches/deno/npm/registry.npmjs.org/@azure/notification-hubs/1.0.0-beta.2/

Azure Notification Hubs uses subpath exports with the following mapping where /models/*.ts should be mapped to such maps as /models/notification.ts:

  "exports": {
    ".": {
      "types": "./types/src/index.d.ts",
      "require": "./dist/index.cjs",
      "import": "./dist-esm/src/index.js"
    },
    "./client": {
      "types": "./types/src/client/index.d.ts",
      "import": "./dist-esm/src/client/index.js"
    },
    "./client/*": {
      "types": "./types/src/client/*.d.ts",
      "import": "./dist-esm/src/client/*.js"
    },
    "./models/*": {
      "types": "./types/src/models/*.d.ts",
      "import": "./dist-esm/src/models/*.js"
    }
  },
@kitsonk kitsonk added bug Something isn't working correctly node compat labels Aug 25, 2022
@bartlomieju
Copy link
Member

@mpodwysocki I fixed the immediate problem you had, but trying to run the same code I get this error:

error: Uncaught SyntaxError: The requested module '@azure/core-util' does not provide an export named 'isObjectWithProperties'
    at <anonymous> (file:///Users/ib/Library/Caches/deno/npm/registry.npmjs.org/@azure/notification-hubs/1.0.0-beta.2/dist-esm/src/auth/sasTokenProvider.js:4:10)

I looked into @azure/core-util where this symbols is supposed to be and there's no such function in there. Are you able to run in this program in Node without a problem?

@bartlomieju
Copy link
Member

Okay, just confirmed, it doesn't work in Node either

file:///Users/ib/dev/azure/node_modules/@azure/notification-hubs/dist-esm/src/auth/sasTokenProvider.js:4
import { isObjectWithProperties } from "@azure/core-util";
         ^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'isObjectWithProperties' not found. The requested module '@azure/core-util' 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/core-util';
const { isObjectWithProperties } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.7.0

@mpodwysocki
Copy link
Author

@bartlomieju apologies for being on vacation. We have fixed the dependency issue and now just getting the error with 1.25.1 with can't load the module. Is there some new flag I'm missing?

~/.deno/bin/deno run --unstable --allow-env --reload index.ts
...
error: Could not find npm package '@azure/notification-hubs' matching 1.0.0-beta.3. Try retreiving the latest npm package information by running with --reload

@bartlomieju
Copy link
Member

@mpodwysocki we had a small regression in v1.25.1 that causes this problem. It's been already fixed and will be released in v1.25.2. If you are not on Mac M1 you can deno upgrade --canary to get it working.

@mpodwysocki
Copy link
Author

@bartlomieju unfortunately, I am on a MacBook Air M1, so I'll have to wait to try it out. Thanks for all your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants