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

add support for functional build.transpile with vite builder #14729

Closed
belomx opened this issue Aug 29, 2022 · 5 comments · Fixed by nuxt/framework#7767
Closed

add support for functional build.transpile with vite builder #14729

belomx opened this issue Aug 29, 2022 · 5 comments · Fixed by nuxt/framework#7767

Comments

@belomx
Copy link

belomx commented Aug 29, 2022

Environment

https://codesandbox.io/s/amazing-minsky-nwzxcr?file=/nuxt.config.js

Reproduction

In the "nuxt.config.js" define the build transpile like:

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({
build: {
transpile: [({ isDev }) => isDev && "lodash"]
}
});

Then execute "npm run build"

Describe the bug

The nuxt build is returns the error in logs section. And lodash is not transpiled.

Additional context

The functionality work properly when the nuxt.config is done in typescript ("nuxt.config.ts").

Config from nuxt documentation.
https://nuxtjs.org/docs/configuration-glossary/configuration-build/#transpile

Logs

WARN  [SSR] Error transforming /sandbox/node_modules/nuxt/dist/app/entry: filename.split is not a function

  at normalizePath (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11471:21)
  at getMatcherString (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11476:16)
  at Object.test (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11495:33)
  at result (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:11511:25)
  at node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38123:38
  at node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38139:41
  at shouldExternalizeForSSR (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:38066:12)
  at TransformContext.transform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:40368:34)
  at async Object.transform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:35579:30)
  at async loadAndTransform (node_modules/vite/dist/node/chunks/dep-0fc8e132.js:39888:29)
@danielroe
Copy link
Member

build.transpile only supports RegExp + strings in Vite. (The function is used for webpack builder only.)

Do you think it's worth adding support for it to vite builder too @pi0? I think it could be useful as someone might want to transpile in server/client context only.

@danielroe danielroe changed the title Error during build when function to conditionally transpile is defined in nuxt.config.js add support for functional build.transpile with vite builder Aug 30, 2022
@danielroe danielroe added the vite label Aug 30, 2022
@pi0
Copy link
Member

pi0 commented Aug 30, 2022

Yes, we added it to Nuxt 2 for webpack too (main usecase was a transpile for nuxt/http module only on server) makes sense to support function entries for transpile accepting env for vite too (universally) 👍🏼

@jmorel88
Copy link
Contributor

@danielroe @pi0 I'd be happy to help out with this one. Would you mind pointing me in the right direction? What directories/files would be a good starting point?

@JoakimFFCG
Copy link

JoakimFFCG commented Nov 21, 2022

The documentation for transpile says:

You can also use a function to conditionally transpile. The function will receive an object ({ isDev, isServer, isClient, isModern, isLegacy }).
Example:
transpile: [({ isLegacy }) => isLegacy && 'ky']

However, when I try to provide a function in the transpile array I always get
[vite-node] [plugin:vite:import-analysis] [VITE_ERROR] /@fs./node_modules/nuxt/dist/app/entry.mjs

If I understand this issue correct the above functionality isn't actually merged yet?
Any ETA for that? Can't see any blockers in the PR.

(And yes, the code example in the documentation is missing isLegacy before &&).

EDIT: The typo in the documentation I quoted was fixed.

@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

Successfully merging a pull request may close this issue.

5 participants