question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot `pd publish` ESM typescript build if it imports from local files

See original GitHub issue

When running pd publish the follow error is encountered:

Detected local requires, creating zip archive...
- actions/myAction/index.js
- api.js
component create api call responded with status: 500, body: {"error":"unexpected error, please contact support@pipedream.com"}

This only happens when I attempt to publish a .js file that imports from another relative local file. If all code is kept in the same file, the issue disappears.

I am compiling down from Typescript with this tsconfig.json:

{
  "compilerOptions": {
    "outDir": "lib",
    "module": "esnext",
    "target": "esnext",
    "lib": ["esnext", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "moduleResolution": "node",
    "jsx": "react",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "noUnusedLocals": false,
    "strictNullChecks": true,
    "noUnusedParameters": true,
    "declaration": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "/lib"]
}

The result of running $ tsc to build is a /lib output folder in .js files that continue to use relative imports. For example, if in the Typescript source code I have import { helper } from "../../api", the same will appear in the compiled Javascript code.

import { helper } from "../../api";   // this stays the same from TS -> JS

My naive suspect is that $ pd publish ./lib/actions/myAction.js is being uploaded individually, however the logging does say that its “Detected local requires, creating zip archive…”. I would be helpful if the error message was more specific.

I really want to use Typescript in all my pipedream workflows, as static typing keeps me sane across so many cloud functions. Is there something I am missing?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
casretcommented, Feb 4, 2022

Yeah, for CJS, we expect the whole component to be exported, not under the default key, which is more of a esm-ism.

1reaction
casretcommented, Feb 4, 2022

Unfortunately not, you are trailblazing, feel free to reach out at any time with questions. We are working on a way to make TS available natively, but we are taking a bit of a different approach.

On Fri, Feb 4, 2022 at 10:46 AM Kangze Huang @.***> wrote:

Ahh good to know! Do you have a pre-built recommended TS config for that? Or an example repo? It would save a lot of time for me & other users.

If not, I will look into it and share here.

— Reply to this email directly, view it on GitHub https://github.com/PipedreamHQ/pipedream/issues/2181#issuecomment-1030255668, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACLBFGFD4LJY725OEOF5LUZQNGRANCNFSM5NSIX6OA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript cannot emit valid ES modules due to file ...
Because TS imports do not allow file extensions, but imports in emitted ES modules are not resolved to their relevant file extensions (...
Read more >
Documentation - ECMAScript Modules in Node.js
When a .ts file is compiled as an ES module, ECMAScript import / export ... it is treated as an ESM or CommonJS...
Read more >
Unable to import ESM .ts module in node
In tsconfig.json (create one if not present) in compilerOptions add the following line: "module": "commonjs". Typescript info page here.
Read more >
Publishing Node modules with TypeScript and ES modules
Publishing Node modules with TypeScript and ES modules · First, create an empty directory and run npm init -y to create a new...
Read more >
TypeScript and native ESM on Node.js
In this blog post, I'll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found