nuxt / bridge

🌉 Experience Nuxt 3 features on existing Nuxt 2 projects
MIT License
273 stars 29 forks source link

Module parse failed: Unexpected token: import.meta #1295

Open wJoenn opened 2 months ago

wJoenn commented 2 months ago

Environment

- Operating System: Linux
- Node Version:     v18.20.3
- Nuxt Version:     2.18.1
- CLI Version:      3.13.0
- Nitro Version:    2.9.7
- Package Manager:  yarn@1.22.19
- Builder:          webpack
- User Config:      bridge, build, modules, ssr, serverHandlers, devServerHandlers, devServer, typescript, nitro, buildModules
- Runtime Modules:  @pinia/nuxt@0.5.4
- Build Modules:    (), @nuxt/bridge@3.3.1

Reproduction

https://stackblitz.com/edit/nuxt-bridge-reproduction?file=nuxt.config.ts

Describe the bug

As discussed in https://github.com/vuejs/pinia/pull/2622#issuecomment-2304813676, installing the latest version of @pinia/nuxt in a nuxt bridge project raises an error because import.meta is not parsable.

Reverting back to a version prior to the before-mentioned PR fixes the issue as it still uses process instead.

Additional context

👋 @danielroe

image

#

Some reasons for the settings in the reproduction:

Logs

No response

wattanx commented 2 months ago

We have checked that it works in the latest edge release. @nuxt/bridge-edge@3.3.1-28745713.5493b4e https://stackblitz.com/edit/github-toccfh

wJoenn commented 2 months ago

Thank you both 🙌

yshrsmz commented 1 month ago

@wattanx hi, I still have the same problem.

It looks like your example does not contain @pinia/nuxt package.

Check the repro here: https://stackblitz.com/edit/github-toccfh-mifppg?file=package.json

yshrsmz commented 1 month ago

@wattanx Thanks for your quick reply!

When I run npx nuxi/@latest module add pinia as described in that instruction, I see @pinia/nuxt is installed and added to the dependencies. (and, I couldn't find any text that we don't need @pinia/nuxt for Nuxt Bridge)

Also, when I run your example(stackblitz.com/edit/github-toccfh), I see the warning log below. Is that ignorable?

WARN  Module @pinia/nuxt not found. Please ensure @pinia/nuxt is in dependencies and installed.    
wattanx commented 1 month ago

It was my mistake to say that installation is not necessary

wJoenn commented 1 month ago

@yshrsmz the fix has been merged but it hasn't been released yet. Follow 3.4's PR https://github.com/nuxt/bridge/pull/1261 if you wanna be notified about when it'll become available

yshrsmz commented 1 month ago

@wJoenn I've tested with @nuxt/bridge-edge@3.3.1-28745713.5493b4e (the latest edge) and @nuxt/bridge-edge@3.3.1-28745713.5493b4e(the version wattanx mentioned), so I think I used the version which includes the change.

my repro is here: https://stackblitz.com/edit/github-toccfh-mifppg

Or did you confirm it's working as intended?

wJoenn commented 1 month ago

No my bad, I'm in mobile right now so I didn't take the time to check your repro. Sorry about that.

If edge doesn't work either then I suppose the fix doesn't work ? I'll let Wattanx answer that

yshrsmz commented 1 month ago

@wattanx Sorry to bother you, but did you confirm the behavior? If my repro is correct, could you please reopen the issue? Or should I create another issue?

wattanx commented 1 month ago

It seems that the issue hasn't been fixed, so I reopened it. By the way, you can migrate to Nuxt 3 without migrating to Pinia if you use the following module https://github.com/wattanx/nuxt-vuex-module https://github.com/vedmant/nuxt3-vuex#nuxt3-vuex-module

medz commented 3 weeks ago
import fs from "fs";

const target = "node_modules/@pinia/nuxt/dist/runtime/plugin.vue2.js";

const contents = fs
  .readFileSync(target, { encoding: "utf-8" })
  .replace("import.meta.server", "process.server");

fs.writeFileSync(target, contents);

I worked around this problem by writing a fix script. It's useful until the issue is fixed properly.