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

Cannot import into Nuxt project #462

Closed
cameronweibel opened this issue Apr 14, 2021 · 3 comments
Closed

Cannot import into Nuxt project #462

cameronweibel opened this issue Apr 14, 2021 · 3 comments

Comments

@cameronweibel
Copy link

Description

Importing this plugin into a Nuxt project and building with npm run start (nuxt generate and nuxt start) is not possible.

Reproduction

Creating a page in Nuxt with the following code:

<template>
  <h1>Hi</h1>
</template>

<script>
import parserJava from "prettier-plugin-java";
</script>

And building, navigating to page, results in an error of:
TypeError: Cannot read property '1' of null at vn (a7816b4.js:2) at e.exports.e.initRecognizerEngine (a7816b4.js:2) at new e (a7816b4.js:2) at new e.exports (a7816b4.js:2) at Object.<anonymous> (a7816b4.js:2) at l (094da21.js:1) at Object.<anonymous> (a7816b4.js:2) at l (094da21.js:1) at Object.<anonymous> (a7816b4.js:2) at l (094da21.js:1)

nuxt-static-error.zip
Run npm i followed by npm run start in this project to see the issue. If you run npm run dev it works.

@cameronweibel
Copy link
Author

Apparently - "This is not a Nuxt-specific issue. The error is being thrown by chevrotain, a dependency of prettier-plugin-java. It is inspecting the source code of a class with a RegExp to try to find a function name - which, because it's built, is different from development mode."

@cameronweibel
Copy link
Author

cameronweibel commented Apr 18, 2021

For anybody else reading this with the same issue, I fixed it with the following build options in nuxt.config.js:

  build: {
      terser: {
          parallel: true,
          cache: false,
          sourceMap: false,
          extractComments: {
              filename: "LICENSES",
          },
          terserOptions: {
              output: {
                  comments: /^\**!|@preserve|@license|@cc_on/,
              },
              keep_fnames: true, <- This lines fixes it
          },
      },
  },

It would be ideal to not have to use this workaround though.

@Shaolans
Copy link
Member

I will be adding this in the documentation.
Thank you for giving this workaround

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

2 participants