Skip to content

Using SSR causes : Cannot use 'import.meta' outside a module #106

@Xstoudi

Description

@Xstoudi

webpack.config.js: https://pastebin.com/TqBTuZNf
webpack.ssr.config.js: https://pastebin.com/7eSR3tD5

As you can see, I use a Inertia-React-Tailwind stack.

When navigating to a route of my app, Adonis throws this error:

[18:50:01.079] ERROR (hydra/18528): Cannot use 'import.meta' outside a module
    err: {
      "type": "SyntaxError",
      "message": "Cannot use 'import.meta' outside a module",
      "stack":
          D:\Programmation\Perso\hydra\build\inertia\ssr\ssr.js:1514
          /******/      if (typeof import.meta.url === "string") scriptUrl = import.meta.url
                                          ^^^^

          SyntaxError: Cannot use 'import.meta' outside a module
              at internalCompileFunction (node:internal/vm:74:18)
              at wrapSafe (node:internal/modules/cjs/loader:1141:20)
              at Module._compile (node:internal/modules/cjs/loader:1182:27)
              at Object.Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
              at Module.load (node:internal/modules/cjs/loader:1081:32)
              at Function.Module._load (node:internal/modules/cjs/loader:922:12)
              at Module.require (node:internal/modules/cjs/loader:1105:19)
              at require (node:internal/modules/cjs/helpers:103:18)
              at Inertia.renderSsrPage (REDACTED\node_modules\@eidellev\inertia-adonisjs\build\src\Inertia.js:97:24)
              at Inertia.render (REDACTED\node_modules\@eidellev\inertia-adonisjs\build\src\Inertia.js:77:47)
      "status": 500
    }

It seems to generate ESM code import.meta that obviously fail.

Did I do something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions