-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Enable to parse shebang in the function ssrTransform #8002
Copy link
Copy link
Closed
Labels
feat: ssrp2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)
Description
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.
vite/packages/vite/src/node/ssr/ssrTransform.ts
Lines 37 to 41 in dddda1e
| 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.2Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: ssrp2-nice-to-haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)