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

Nitro bundling does not seem to convert the typescript decorator. #14080

Closed
izure1 opened this issue Jun 5, 2022 · 10 comments
Closed

Nitro bundling does not seem to convert the typescript decorator. #14080

izure1 opened this issue Jun 5, 2022 · 10 comments

Comments

@izure1
Copy link

izure1 commented Jun 5, 2022

Environment

  • Operating System: Windows_NT
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: npm@8.3.0
  • Builder: vite
  • User Config: typescript, app, css, build, runtimeConfig, vite
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://codesandbox.io/s/sleepy-mestorf-hh7edv?file=/server/utils/sequelize.ts

Describe the bug

I apologize for my poor English and use a translator.

If the source code includes a typescript decorator, the bundling of rollup does not end.
I think it's the same issue as the #14062 post.

Here are the results of the my nuxi dev:

Vite client warmed up in 9811ms 00:02:29
Vite server warmed up in 430ms 00:02:31
Vite server built in 12457ms

I checked exactly where it stopped.

And the esbuild rollup plugin used in the getRollupConfig function in the node_modules/nitropack/dist/chunks/prerender.mjs file does not seem to process files that use typescript decorators.
And I found out that the autoImport plugin excluded files that are using decorators from the processing list.

One weird thing is, after the first nuxt app was created, it worked.
This issue occurred after deleting the node_modules folder and reinstalling all packages.

I deleted the file node_modules, .vite, .nuxt, package-lock.json, and deleted the cache using the npm clean verify command. Nevertheless, the problem has not been solved.

Also, after deleting the node_modules folder and reinstalling the package, an explicit installation of the @nuxt/vite-builder package was required. This was not required immediately after the app was created with the nuxi command.

I've prepared minimal reproduction, but I don't know how it'll work.

Additional context

No response

Logs

No response

@djschilling
Copy link

this seems to make sense, i also use decorators for the package typeorm and i created the issue #14062. How can we further debug this and get it working again?

@izure1
Copy link
Author

izure1 commented Jun 9, 2022

@djschilling I solved the problem by adding the following settings.

npm i -D rollup-plugin-typescript2

And in the nuxt.config.js file,

import rollupPluginTs from 'rollup-plugin-typescript2'

export default defineNuxtConfig({
  nitro: {
    rollupConfig: {
      plugins: [
        rollupPluginTs()
      ]
    }
  }
})

However, it would be better if the typescript decorator is supported by nuxt3 by default.

@pi0
Copy link
Member

pi0 commented Jun 9, 2022

We use ESBuild to transform typescript files both with Vite and Nitro. Last update for decorator support: evanw/esbuild#104 (comment)

I think adding rollup plugin would be the best.

@issue-up
Copy link

issue-up bot commented Jun 9, 2022

@pi0
Copy link
Member

pi0 commented Jun 9, 2022

Thanks for the followup @izure1. I've escalated this to #14126 and nitrojs/nitro#273 for having an experimental flag for built-in support while ESBuild and Spec are stable.

@pi0 pi0 closed this as completed Jun 9, 2022
@djschilling
Copy link

@izure1 thanks for the tip. Now its at least throwing an error.


 WARN  Multiple major versions of package parse5 are being externalized. Picking latest version.                                                                         16:36:33
  - /Users/david/projects/work/finder/churchtools-finder/node_modules/parse5@5.1.1
  - /Users/david/projects/work/finder/churchtools-finder/node_modules/parse5-htmlparser2-tree-adapter/node_modules/parse5@6.0.1


 ERROR  Rollup error: Could not resolve './scheduler' from ./scheduler?commonjs-external                                                                           nitro 16:36:34


 ERROR  Could not resolve './scheduler' from ./scheduler?commonjs-external                                                                                               16:36:34

  at error (node_modules/rollup/dist/es/shared/rollup.js:1858:30)
  at ModuleLoader.handleResolveId (node_modules/rollup/dist/es/shared/rollup.js:22375:24)
  at node_modules/rollup/dist/es/shared/rollup.js:22338:26

Did you also get this error?

@izure1
Copy link
Author

izure1 commented Jun 9, 2022

@djschilling In my case, I used the sequelize-typescript library, and there was no such error.

@BracketJohn
Copy link
Contributor

BracketJohn commented Jul 15, 2022

Brief update:

The fix of @izure1 worked out in RC2-RC4, with RC5 it stopped working and we get the error from above again:

start Building server...                                                                                                                                                      nitro 12:48:20

 WARN  Multiple major versions of package parse5 are being externalized. Picking latest version.                                                                                    12:48:28
  - app/node_modules/cli-highlight/node_modules/parse5@5.1.1
  - app/node_modules/parse5@6.0.1

 ERROR  Rollup error: Could not load /app/.nuxt/dist/server/server.mjs (imported by node_modules/nuxt/dist/core/runtime/nitro/renderer.mjs): ENOENT: no such file or directory, open '/app/.nuxt/dist/server/server.mjs'

 ERROR  Could not load /app/.nuxt/dist/server/server.mjs (imported by node_modules/nuxt/dist/core/runtime/nitro/renderer.mjs): ENOENT: no such file or directory, open '/app/.nuxt/dist/server/server.mjs'

@izure1
Copy link
Author

izure1 commented Jul 15, 2022

@BracketJohn Since rc.4 version and later, TypeScript Decorator is supported by default, so you no longer need to use the plugin.

@BracketJohn
Copy link
Contributor

Ah nice, thanks for the info, that's awesome!

Anyways, regarding my report: I think then this problem is probably the same as #14320!

Sorry for the intrusion here ✋

alee referenced this issue in virtualcommons/port-of-mars Sep 16, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants