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

Adding typescript plugin via addPlugin isn't transpiled into js #10619

Closed
GM-Alex opened this issue Aug 3, 2022 · 7 comments
Closed

Adding typescript plugin via addPlugin isn't transpiled into js #10619

GM-Alex opened this issue Aug 3, 2022 · 7 comments

Comments

@GM-Alex
Copy link

GM-Alex commented Aug 3, 2022

Versions

  • nuxt: 2.15.8
  • node: v16.15.1

Reproduction

Create a plugin with Typescript and add it via a module with the following code:

this.addPlugin({
    src: path.resolve(__dirname, 'plugin.ts'),
    fileName: 'plugin.js',
    options
});

Steps to reproduce

see above

What is Expected?

plugin.ts is transpiled into plugin.js

What is actually happening?

The plugin code is copied to the .nuxt build folder as plugin.js but still in typescript instead of javascript.

@bianliuzhu
Copy link

Nice to talk to you. I am a developer in China, I like the framework of NUXT very much, But it also brings me some troubles Because we do not know much about the bottom implementation and operating principle of NUXT.
About the following four issues, I hope to get a little inspiration from you thank you very much

I use NUXT2

Will using Vuex reduce performance?
Will Vuex run on the server? and will vuex data be downloaded from the server to the client?
Does the use of Vuex increase the memory?
The same state, what is the difference between storing in vuex and storing in components

@avxkim
Copy link

avxkim commented Mar 20, 2023

@danielroe nuxt 2.16, issue remains!

Copy link
Member

What makes you think these files should be transpiled? Would you provide a reproduction? Are you using nuxt/typescript-build?

@danielroe
Copy link
Member

Just checking this out, this works fine with nuxt/typescript-build, assuming you copy it with fileName: 'plugin.ts'. And Nuxt 2 does not otherwise have support for TypeScript, so I think we can safely close this.

It is worth adding that Nuxt 3 has built-in support for TypeScript.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2023
@avxkim
Copy link

avxkim commented Mar 21, 2023

Just checking this out, this works fine with nuxt/typescript-build, assuming you copy it with fileName: 'plugin.ts'. And Nuxt 2 does not otherwise have support for TypeScript, so I think we can safely close this.

It is worth adding that Nuxt 3 has built-in support for TypeScript.

Yes, i do have nuxt/typescript-build installed:

  buildModules: [
    // https://go.nuxtjs.dev/typescript
    '@nuxt/typescript-build',
    '@nuxtjs/eslint-module',
    '@nuxtjs/vuetify',
    '@nuxtjs/date-fns',
    '@nuxtjs/composition-api/module',
  ],

And still it doesn't transpile as you said.

This is contents of my custom module index.ts:

import type { Module } from '@nuxt/types'
import { resolve } from 'path'

const sharedModule: Module = function () {
  this.addPlugin({
    src: resolve(__dirname, 'lib/plugins/plugin.ts'),
    mode: 'client',
  })
}

export default sharedModule

I also forgot to mention, i'm using this within monorepo: nx + nx-plus/nuxt: ZachJW34/nx-plus#285

@danielroe
Copy link
Member

Here's a working example: https://stackblitz.com/edit/github-gqugvr.

@avxkim
Copy link

avxkim commented Apr 1, 2023

@danielroe it works, when the module is a part of your app, but in case if you use NX monorepo, there's different folder structure:

-apps
--my_app
---nuxt.config.js
-libs
--shared

obviously it's not transpiling external modules/plugins

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

4 participants