Skip to content

Enable to parse shebang in the function ssrTransform #8002

@togami2864

Description

@togami2864

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp2-nice-to-haveNot breaking anything but nice to have (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions