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

Enable to parse shebang in the function ssrTransform #8002

Closed
7 tasks done
togami2864 opened this issue May 3, 2022 · 1 comment · Fixed by #8005
Closed
7 tasks done

Enable to parse shebang in the function ssrTransform #8002

togami2864 opened this issue May 3, 2022 · 1 comment · Fixed by #8005
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@togami2864
Copy link
Contributor

togami2864 commented May 3, 2022

Describe the bug

This is more of vite-node bug than vite bug.

Currently, vite-node can't execute code containing shebang with the following error.(ref: issue)

Error: Parse failure: Unexpected character '!' (1:1)
Contents of line 1: #!/usr/bin/env node

vite-node uses ssr mode of the vite to transform and the error occurred when parse the code with acron (Internally use the function ssrTransform)

I think adding allowhashBang option in this line can solve this problem.

ast = parser.parse(code, {
sourceType: 'module',
ecmaVersion: 'latest',
locations: true
})

This change would make both vitest and vite-node to run the code with shwbang.

ref:
PR

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-3ctfkq?file=index.ts

System Info

System:
    OS: macOS 11.5.2
    CPU: (8) arm64 Apple M1
    Memory: 75.00 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.13.2/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 100.0.4896.127
    Safari: 14.1.2

Used Package Manager

pnpm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented May 3, 2022

Make sense to me. Feel free to send a PR!

@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: ssr and removed pending triage labels May 3, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants