question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When entry file has a shebang, output it in the first line of the bundle

See original GitHub issue

🙋 feature request

In UNIX systems, the first line of a script can be a shebang with the path to the interpreter. When the main entry file has this shebang (and optionally when target: node), this shebang line could be taken out of the bundled modules and outputted in the first line of the bundle.

🤔 Expected Behavior

hello-world.js:

#!/usr/bin/env node

console.log("Hello, world!");
$ parcel build -t node hello-world.js

dist/hello-world.js:

#!/usr/bin/env node

// parcel bundle prologue ...function(require,module,exports) {
console.log("Hello, world!");
// }... parcel bundle epilogue

😯 Current Behavior

dist/hello-world.js:

// parcel bundle prologue ...function(require,module,exports) {
#!/usr/bin/env node
console.log("Hello, world!");
// }... parcel bundle epilogue

(which is actually a SyntaxError)

🔦 Context

I run into this when trying to make executable scripts for node which have all their files already bundled.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
mischniccommented, Apr 29, 2022

You need to make sure Parcel knows that you’re build for a Node target, not for the browser. The easiest way to achieve that is adding

  "engines": {
    "node": ">=10"
  }

to your package.json

3reactions
cpreciosocommented, Dec 10, 2018

@sintloer That’s great, I’ll start using it! Maybe you could copy the shebang of the entry file instead of having to define it in the package.json?

However, I still think parcel should have native support for this, especially as the input is a valid node script but the output is as SyntaxError.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why should the shebang line always be the first line?
The shebang must be the first line because it is interpreted by the kernel, which looks at the two bytes at the start...
Read more >
How to Use the Shebang in Bash and Python - Linode
A Shebang directive, which always begins with the sequence #! , can sometimes be found on the first line of a Bash or...
Read more >
Shebang (Unix) - Wikipedia
In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark ( #!) at the beginning of...
Read more >
What is the language that appears on the first line of a script?
It's called a shebang. en.wikipedia.org/wiki/Shebang_(Unix). When Unix loads this file into memory, the #! tells the exec function to make use ...
Read more >
webpack-shebang-plugin - npm
#!/usr/bin/env node // The first line is the shebang you want be added. ... two different entries, and you wish to have two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found