edemaine / fold

FOLD file format for origami models, crease patterns, etc.
MIT License
314 stars 48 forks source link

backtick issue in file.coffee #18

Closed amandaghassaei closed 4 years ago

amandaghassaei commented 6 years ago

I don't know enough about coffeescript to fix this myself, but there is an issue in lines 2/3 of https://github.com/edemaine/fold/blob/master/src/file.coffee

when I npm install the fold package in my project I get a file.js file that reads:

!/usr/bin/node

; var convert, file, fs, path; ....

which throws an error. Node sure if the backticks need to be on the same line or gone, but something is not happy.

edemaine commented 6 years ago

That file looks valid... What's the error?

amandaghassaei commented 6 years ago

./node_modules/fold/lib/file.js Module parse failed: Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type. | #!/usr/bin/node | ; | var convert, file, fs, path;

amandaghassaei commented 6 years ago

if I comment out the #!/usr/bin/node it works fine

edemaine commented 6 years ago

Can you try 0.9.12?

amandaghassaei commented 6 years ago

still throwing an error

./node_modules/fold/lib/file.js Module parse failed: Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type. | #!/usr/bin/env node | ; | var convert, file, fs, path;

edemaine commented 6 years ago

Just to confirm: you're running ./node_modules/fold/lib/file.js from bash (Terminal)?

amandaghassaei commented 6 years ago

This is all happening inside a webpack development server. Here is the stack trace:

Uncaught Error: Module parse failed: Unexpected character '#' (1:0) You may need an appropriate loader to handle this file type. | #!/usr/bin/env node | ; | var convert, file, fs, path; at Object../node_modules/fold/lib/file.js (convert.js:266) at webpack_require__ (bootstrap 16e0656…:678) at fn (bootstrap 16e0656…:88) at Object../node_modules/fold/lib/index.js (index.js:6) at webpack_require (bootstrap 16e0656…:678) at fn (bootstrap 16e0656…:88) at Object../src/OrigamiSimulator/PatternImporter.js (PatternImporter.js:13) at webpack_require (bootstrap 16e0656…:678) at fn (bootstrap 16e0656…:88) at Object../src/index.js (index.css?f255:26) at webpack_require (bootstrap 16e0656…:678) at fn (bootstrap 16e0656…:88) at Object.0 (Controls.css?6a69:26) at webpack_require__ (bootstrap 16e0656…:678) at bootstrap 16e0656…:724 at bootstrap 16e0656…:724

line 13 of /src/OrigamiSimulator/PatternImporter.js is: const FOLD = require('fold');

when I comment out the bash line at the top of file.js, everything works fine. It's trying to parse as js and getting stuck on the #.

edemaine commented 6 years ago

Ah, I see. Webpack would have been helpful to mention. I forgot that # is a comment in CoffeeScript but not JavaScript.

It looks like many packers offer workarounds for this, but Webpack requires you to include shebang-loader... See https://github.com/webpack/webpack/issues/2168 and https://github.com/webpack/webpack/issues/4603 Kinda inconvenient though. I'm open to other possibilities, but it'd be a shame to lose the executability of the file... Maybe should write a shell script interface that runs node.

amandaghassaei commented 6 years ago

oh I see - sorry, didn't realize webpack was any different than regular node. I'll look into these options. thanks!