[ 
https://issues.apache.org/jira/browse/THRIFT-6368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18120389#comment-18120389
 ] 

Jens Geyer commented on THRIFT-6368:
------------------------------------

Good catch!

> js:node,esm generates require() for the parent of an extended service
> ---------------------------------------------------------------------
>
>                 Key: THRIFT-6368
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6368
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Compiler
>    Affects Versions: 0.24.0
>            Reporter: Hampus Adolfsson
>            Assignee: Hampus Adolfsson
>            Priority: Major
>             Fix For: 0.26.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> With `--gen js:node,esm`, a service that `extends` another service is 
> generated with a CommonJS
> `require()` for the parent service, while the rest of the file uses ESM 
> `import`s:
> {code:js}
> import
> { Thrift }
> from 'thrift';
> ...
> const Base = require('./Base.mjs');
> const BaseClient = Base.Client;
> const BaseProcessor = Base.Processor;
> import * as ttypes from './derived_types.mjs';
> {code}
> Loading the file in Node fails:
> {code}
> ReferenceError: require is not defined in ES module scope, you can use import 
> instead
> {code}
> Reproduction:
> {code}
> service Base { string ping() }
> service Derived extends Base { string hello() }
> {code}
> `thrift --gen js:node,esm test.thrift`, then `node -e 
> "import('./gen-nodejs/Derived.mjs')"`



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to