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

Unexpected token '!' #1066

Closed
Eddie344 opened this issue Jan 13, 2024 · 5 comments
Closed

Unexpected token '!' #1066

Eddie344 opened this issue Jan 13, 2024 · 5 comments

Comments

@Eddie344
Copy link

Environment

  • Operating System: Darwin
  • Node Version: v20.11.0
  • Nuxt Version: 2.17.3
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: yarn@1.22.19
  • Builder: webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Usual nuxt 2 project with @nuxtjs/composition-api v0.31.0

I'm going through nuxt bridge migration guide.
I try to set anything inside bridge field inside nuxt.config, for example:

bridge {
  typescript: true
}

When bridge: false, everything is ok

Describe the bug

image image

Additional context

No response

Logs

No response

@Eddie344
Copy link
Author

Also I tried other node js versions: 16, 18

Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v2-bridge
👉 https://codesandbox.io/p/github/nuxt/starter/v2-bridge-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@wattanx
Copy link
Collaborator

wattanx commented Jan 14, 2024

Maybe it is the same as #1063.

@Eddie344
Copy link
Author

Eddie344 commented Jan 15, 2024

I found the reason: the problem was in my server middleware for recaptcha

import { readBody } from 'h3';
import { ofetch } from 'ofetch';

const SECRET_KEY = process.env.RECAPTCHA_PRIVATE_KEY;

export default async (req, res) => {
  res.setHeader('Content-Type', 'application/json');

  // eslint-disable-next-line no-unreachable
  try {
    const { token } = await readBody({ node: { req }, method: 'POST' });

    if (!token) {
      res.end(
        JSON.stringify({
          success: false,
          message: 'Invalid token',
        }),
      );
      return;
    }

    const response = await ofetch(
      `https://www.google.com/recaptcha/api/siteverify?secret=${SECRET_KEY}&response=${token}`,
      {
        method: 'POST',
      },
    );

    res.end(
      JSON.stringify({
        success: response.success,
        response,
      }),
    );
  } catch (error) {
    console.error(error);
    res.end(
      JSON.stringify({
        success: false,
        message: 'Internal error',
        error,
      }),
    );
  }
};

I have not figured out exactly what the problem is, just turn off this file

@kyumoon
Copy link

kyumoon commented Aug 28, 2024

I found the cause.
import http from "node:http" doesn't work properly with webpack + bridge.
Before switching to vite, we can use path-package to fix it

-import http from 'node:http';
-import https from 'node:https';
+import http from 'http';
+import https from 'https';

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

3 participants