martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

SWC #237

Closed martpie closed 2 years ago

martpie commented 2 years ago

It looks like Next.js is experimenting with SWC. Investigate what it means for this plugin.

karol-f commented 2 years ago

I'm really waiting for that. Using experimental SWC option on current Next canary versions, with:

experimental: {
    swcMinify: true,
    swcLoader: true
}

seems to work till next-transpile-module module is approached:

    |
101 |         delete<SRT, QPT extends DefaultQueryParametersType = undefined, BPT = undefined>(
    |               ^

error: Expected ',', got '< (jsx tag start)

so basically it does not treat this file as typescript one. However typescript detection in next-swc-loader seems to work ok - https://github.com/vercel/next.js/blob/00431087d7ce2126bc819472cb3b71dbaefd46f7/packages/next/build/webpack/loaders/next-swc-loader.js#L108

martpie commented 2 years ago

@karol-f which version are you using exactly? I'm getting weird errors:

error - ../node_modules/next/dist/pages/_app.js
Error: Failed to deserialize argument at `2` as next_swc::TransformOptions
JSON: {"jsc":{"parser":{"syntax":"ecmascript","dynamicImport":true,"jsx":true},"transform":{"react":{"runtime":"automatic","pragma":"React.createElement","pragmaFrag":"React.Fragment","throwIfNamespace":true,"development":true,"useBuiltins":true}}},"disableNextSsg":true,"allowWrongLineComments":true,"pagesDir":"/Users/pmartiniere/dev/next-transpile-modules/src/__tests__/__apps__/swc/app/pages","env":{"targets":{"node":"16.11.1"}},"filename":"/Users/pmartiniere/dev/next-transpile-modules/src/__tests__/__apps__/swc/node_modules/next/dist/pages/_app.js","sourceMaps":true,"inlineSourcesContent":true,"sourceFileName":"/Users/pmartiniere/dev/next-transpile-modules/src/__tests__/__apps__/swc/node_modules/next/dist/pages/_app.js"}

Caused by:
    unknown field `allowWrongLineComments` at line 1 column 726
karol-f commented 2 years ago

The newest canary (from today) - so next@canary + proper experimental key settings in next.config.js.

If you need some setup or GitHub repo example I can prepare one.

martpie commented 2 years ago

It looks like things work out of the box in canary.80. Stick to this version and don't use @canary, your build could break any time.