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

run versionBumpp function in a mjs file #9

Closed
5 tasks done
honghuangdc opened this issue Jun 4, 2023 · 2 comments · Fixed by #22
Closed
5 tasks done

run versionBumpp function in a mjs file #9

honghuangdc opened this issue Jun 4, 2023 · 2 comments · Fixed by #22

Comments

@honghuangdc
Copy link

honghuangdc commented Jun 4, 2023

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

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@honghuangdc honghuangdc changed the title TS type ReleaseType in build chunk run versionBumpp function in a mjs file Jun 4, 2023
@murongg
Copy link

murongg commented Nov 16, 2023

same error

@dockfries
Copy link

dockfries commented Nov 23, 2023

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/picocolors@1.0.0/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants