bumpp icon indicating copy to clipboard operation
bumpp copied to clipboard

run versionBumpp function in a mjs file

Open honghuangdc opened this issue 2 years ago • 2 comments

Describe the bug

Here are the steps to reproduce the error:

  1. create a mjs file
  2. import versionBumpp from 'bumpp';
  3. run versionBumpp function

import { ReleaseType } from "semver"; ^^^^^^^^^^^ SyntaxError: Named export 'ReleaseType' not found. The requested module 'semver' 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 'semver'; const { ReleaseType } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)

I found a TS type declaration ReleaseType in dist/chunk-L3LY4KGC.mjs.

Reproduction

https://stackblitz.com/edit/stackblitz-starters-7ky89b?file=index.mjs

System Info

System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.81 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/Library/Caches/fnm_multishells/41379_1685869881245/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/41379_1685869881245/bin/yarn
    npm: 8.11.0 - ~/Library/Caches/fnm_multishells/41379_1685869881245/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 16.5

Used Package Manager

pnpm

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [X] The provided reproduction is a minimal reproducible of the bug.

honghuangdc avatar Jun 04 '23 09:06 honghuangdc

same error

murongg avatar Nov 16 '23 12:11 murongg

import type 就不会打包到 mjs 里去,看起来是 tsup 打包的问题。 @types/semver 声明了这个typesemver 实际上没有导出。

// src > release-type.ts
import type { ReleaseType } from "semver";

但是打包后直接运行 node .\dist\index.mjs 或者 import { versionBump } from "./dist/index.mjs"; 会报 Dynamic require of "tty" is not supported,查了下是tsup打包esm时遇到cjs模块生成的require无效

file:///D:/Work/bumpp/dist/chunk-DHK6LOKB.mjs:29
  throw Error('Dynamic require of "' + x + '" is not supported');
        ^

Error: Dynamic require of "tty" is not supported
    at file:///D:/Work/bumpp/dist/chunk-DHK6LOKB.mjs:29:9
    at node_modules/.pnpm/[email protected]/node_modules/picocolors/picocolors.js (file:///D:/Work/bumpp/dist/chunk-DHK6LOKB.mjs:66:16)
    at __require2 (file:///D:/Work/bumpp/dist/chunk-DHK6LOKB.mjs:44:50)
    at file:///D:/Work/bumpp/dist/chunk-DHK6LOKB.mjs:661:34
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.7.0

dockfries avatar Nov 23 '23 09:11 dockfries