Skip to content

grpc-web: Importing as ESModule in Node #1171

Description

@tommie

Versions of relevant software used

  • Node v19
  • grpc-web v1.5.1
  • webpack: 5.88.1
  • webpack-cli: 4.10.0

What happened

Similar to #369, attempting to run this (named repro.mjs) under Node fails:

import { grpc } from "@improbable-eng/grpc-web";

with

import { grpc } from "@improbable-eng/grpc-web";                                             
         ^^^^                    
SyntaxError: Named export 'grpc' not found. The requested module '@improbable-eng/grpc-web' 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:           

What you expected to happen

No error.

How to reproduce it (as minimally and precisely as possible):

https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-uuifs3?file=repro.js&view=editor

Run npm run repro

It looks like building for ESM (as originally suggested in #369) and adding an exports.import field in package.json makes it importable: https://github.com/improbable-eng/grpc-web/compare/master...tommie:grpc-web:esm?expand=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions