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

H3 error when building nuxt module #353

Closed
Baroshem opened this issue Mar 7, 2023 · 5 comments
Closed

H3 error when building nuxt module #353

Baroshem opened this issue Mar 7, 2023 · 5 comments

Comments

@Baroshem
Copy link

Baroshem commented Mar 7, 2023

Environment

Node: 16.14
npm: 8.3.1
package-manager: yarn
nuxt: 3.2.3
nuxt-security: 0.11.0 -> Aiming to publish 0.12.0 but cannot due to this error

Reproduction

Run yarn prepack in https://github.com/Baroshem/nuxt-security

Describe the bug

After running yarn prepack to build a module following appears:

image

Additional context

It seems to be pointing to:

import * as ufo from 'ufo';

in node_modules/h3/dist/index.d.ts

Logs

SyntaxError: Unexpected token (7:5) in /Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/h3/dist/index.d.ts
    at Object.pp$4.raise (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:20009:13)
    at Object.pp$9.unexpected (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17310:8)
    at Object.pp$9.semicolon (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17287:66)
    at Object.pp$8.parseExpressionStatement (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17770:8)
    at Object.pp$8.parseStatement (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17503:24)
    at Object.pp$8.parseTopLevel (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17367:21)
    at Object.parse (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17139:15)
    at Function.parse (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:17189:35)
    at Graph.contextParse (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/rollup/dist/es/shared/rollup.js:23503:38)
    at tryParse (file:///Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/unbuild/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12) {
  pos: 316,
  loc: {
    column: 5,
    file: '/Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/h3/dist/index.d.ts',
    line: 7
  },
  raisedAt: 328,
  frame: "5: import * as ufo from 'ufo';\n" +
    '6: \n' +
    '7: type SessionDataT = Record<string, any>;\n' +
    '        ^\n' +
    '8: type SessionData<T extends SessionDataT = SessionDataT> = T;\n' +
    '9: interface Session<T extends SessionDataT = SessionDataT> {',
  id: '/Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/h3/dist/index.d.ts',
  hook: 'resolveId',
  code: 'PLUGIN_ERROR',
  plugin: 'commonjs--resolver',
  watchFiles: [
    '/Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/src/module.ts',
    '/Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/src/types.ts',
    '/Users/jakubandrzejewski/Coding/open-source/nuxt/nuxt-security/node_modules/h3/dist/index.d.ts'
  ]
}
error Command failed with exit code 1.
@Baroshem
Copy link
Author

Baroshem commented Mar 7, 2023

I just recently migrated h3-cors package to native CORS in H3, maybe this can be a cause of the issue?

@Baroshem
Copy link
Author

Baroshem commented Mar 9, 2023

Hey @pi0

Do you have any idea about this bug?

It stopps me from releasing a new version of the Security module :(

@Baroshem
Copy link
Author

Baroshem commented Mar 9, 2023

I managed to find a solution.

Basically, I cannot import files from h3 in the module.ts file in Nuxt module. I created types locally to fix this.

@Baroshem Baroshem closed this as completed Mar 9, 2023
@nozomuikuta
Copy link
Member

@Baroshem

Seeing the error message, you might have been facing at unjs/unbuild#135.

At the moment, unfortunately, there seems to be no way to fix it or provide workaround on user side, because nuxt module builder accepts just few of unbuild options from user (ref).

@Baroshem
Copy link
Author

Baroshem commented Mar 9, 2023

Thanks for clarification @nozomuikuta ! I managed to fix it by not using the types from h3 in my module

@pi0 pi0 reopened this Mar 10, 2023
@pi0 pi0 closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants