nuxt / module-builder

Complete solution to build and ship Nuxt modules.
MIT License
212 stars 23 forks source link

pnpm pack error after 3.12.3 upgrade #309

Open matt-clegg opened 2 days ago

matt-clegg commented 2 days ago

Environment

Operating System: Linux Node Version: v20.5.1 Nuxt Version: 3.12.3 CLI Version: 3.12.0 Nitro Version: 2.9.7 Package Manager: pnpm@9.4.0 Builder: - User Config: - Runtime Modules: - Build Modules: -

This was also running inside a Docker container, using node:20.5-bullseye-slim as a base image.

Reproduction

I'm unable to create a reproduction of this issue as this from a large, internal project. This issue happens in our CI pipeline.

Describe the bug

After upgrading to Nuxt v3.12.3 our CI pipeline has started erroring when running pnpm pack.

This is the error:

RUN pnpm pack

> @xxxx/yyyy@0.1.634-PullRequest6728.5 prepack /src
> nuxt-module-build

 WARN  Please specify the build command explicitly. In a future version of @nuxt/module-builder, the implicit default build command will be removed.

ℹ Building yyyyy
ℹ Cleaning dist directory: ./dist

 ERROR  Cannot read properties of undefined (reading 'includes')

  at node_modules/.pnpm/@nuxt+module-builder@0.8.1_@nuxt+kit@3.12.3_magicast@0.3.4_rollup@4.18.0__nuxi@3.12.0_sass@1._h47tfeevekwjm42weg4tnyrm3q/node_modules/@nuxt/module-builder/dist/chunks/build.mjs:171:86
  at Array.find (<anonymous>)
  at hasTypeExport (node_modules/.pnpm/@nuxt+module-builder@0.8.1_@nuxt+kit@3.12.3_magicast@0.3.4_rollup@4.18.0__nuxi@3.12.0_sass@1._h47tfeevekwjm42weg4tnyrm3q/node_modules/@nuxt/module-builder/dist/chunks/build.mjs:171:62)
  at writeTypes (node_modules/.pnpm/@nuxt+module-builder@0.8.1_@nuxt+kit@3.12.3_magicast@0.3.4_rollup@4.18.0__nuxi@3.12.0_sass@1._h47tfeevekwjm42weg4tnyrm3q/node_modules/@nuxt/module-builder/dist/chunks/build.mjs:177:7)
  at async rollup:done (node_modules/.pnpm/@nuxt+module-builder@0.8.1_@nuxt+kit@3.12.3_magicast@0.3.4_rollup@4.18.0__nuxi@3.12.0_sass@1._h47tfeevekwjm42weg4tnyrm3q/node_modules/@nuxt/module-builder/dist/chunks/build.mjs:145:11)
  at async rollupBuild (node_modules/.pnpm/unbuild@2.0.0_sass@1.77.6_typescript@5.5.3_vue-tsc@1.8.27_typescript@5.5.3_/node_modules/unbuild/dist/index.mjs:721:3)
  at async _build (node_modules/.pnpm/unbuild@2.0.0_sass@1.77.6_typescript@5.5.3_vue-tsc@1.8.27_typescript@5.5.3_/node_modules/unbuild/dist/index.mjs:1087:3)
  at async build (node_modules/.pnpm/unbuild@2.0.0_sass@1.77.6_typescript@5.5.3_vue-tsc@1.8.27_typescript@5.5.3_/node_modules/unbuild/dist/index.mjs:945:5)
  at async Object.run (node_modules/.pnpm/@nuxt+module-builder@0.8.1_@nuxt+kit@3.12.3_magicast@0.3.4_rollup@4.18.0__nuxi@3.12.0_sass@1._h47tfeevekwjm42weg4tnyrm3q/node_modules/@nuxt/module-builder/dist/chunks/build.mjs:43:5)
  at async runCommand (node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs:316:16) 

Our CI pipeline was running fine before upgrading to v3.12.3. I'm wondering if anyone else has seen this and what might have changed in this release for the pack command to break like this. Unfortunately there is no other information in the lofs that point to lines in our codebase.

I cant supply our source code as it's internal to our company. I hope this error is enough to be pointed in the right direction. I can provide other information, if needed.

Additional context

No response

Logs

No response

github-actions[bot] commented 2 days ago

Would you be able to provide a reproduction? 🙏

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz 👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
matt-clegg commented 1 day ago

I've think managed to reproduce the issue. The error was happening in our module.

Inside our module.ts file we have the following line: export * from "./runtime/composables/resources/generated/types";

This points to a file with about 3.4k lines of auto-generated types from our backend, this file was generated by NSwag. It looks something like:

// ----------------------
// <auto-generated>
//     Generated using the NSwag toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// </auto-generated>
// ----------------------

export interface FooRepresentation {
  key: string;
  label: string;
  url: string;
}

export interface BarDto {
  title?: string | undefined;
  description: string | undefined;
  flag: boolean;
}

// 3000 more lines of interfaces and enums...

Commenting out the line in module.ts to export the types allows the pnpm pack command to complete.

matt-clegg commented 20 hours ago

So it seems the issue is caused by specifying a file inside the runtime folder is causing the pnpm pack error. I moved the generated types out of the runtime folder and changed the export command from export * from "./runtime/composables/resources/generated/types"; to export * from "./generated-types", and the pack command worked.

Should I no longer be exporting types from inside the runtime directory, or has a Nuxt change broken this functionality?