sveltejs / svelte-cli

Command line interface for Svelte
MIT License
105 stars 18 forks source link

Cannot compile on Windows 7 #5

Closed thephilwells closed 7 years ago

thephilwells commented 7 years ago

I tried following along with the Getting Started section of the guide.

First, I ran this: echo "<h1>Hello {{name}}</h1>" > HelloWorld.html

Then I ran this: svelte compile --format iife .\HelloWorld.html > HelloWorld.js

This caused an empty HelloWorld.js file to be generated, and returned the following error:

compiling HelloWorld.html...

C:\Users\\Roaming\npm\node_modules\svelte-cli\node_modules\svelte\dist\svelte.js:4138
                        throw new ParseError( message, this.template, index );
                        ^
ParseError: Expected valid tag name

Running on Windows 7, x64 Node v6.5.0 svelte-cli installed globally using npm v3.10.6

michaelkacher commented 7 years ago

I ran into the same exact error. Running: Windows 10 x64 Node v6.9.1

I am going to try on linux to see if I can get it to work there.

jacobmischka commented 7 years ago

It actually just gives that error if there's a syntax error in your svelte code, are you sure it's correct? Does it work in the REPL?

michaelkacher commented 7 years ago

For me it works in the REPL and works when I use Windows subsystem for Linux.

keawade commented 7 years ago

I'm getting the same error in Windows 10 x64. Using Windows Subsystem for Linux gives me the same result.

Rich-Harris commented 7 years ago

What does the HelloWorld.html file look like after running the echo command? It sounds like maybe it's getting borked up at that stage.

keawade commented 7 years ago

<h1>Hello {{name}}</h1>

Same as the text in the example. I've tried copy/pasting it in and typing it in manually.

mrkishi commented 7 years ago

That happens because echo "<h1>Hello {{name}}</h1>" > HelloWorld.html results in a UTF-16 LE-encoded file, while svelte-cli expects a UTF-8 file.

I guess this should be noted in the documentation. As far as I know, auto-detecting file encodings isn't a very reliable operation.

keawade commented 7 years ago

Okay.

I deleted my HelloWorld.html file and created a new one without using echo and it worked fine! Thanks!

We should fix this in the documentation since using echo is explicitly called for in the tutorial.

As to the encoding, perhaps a flag could be added to the command to specify an encoding different than the default?

Ryuno-Ki commented 7 years ago

You would need to pipe it through iconv since echo has no option for it on its own.

Since I assume, the encoding is specific to your installation, could you test that, @mrkishi, @keawade?

mrkishi commented 7 years ago

I think simply noting it in the documentation should be enough. It seems like most other js cli (such as babel and uglifyjs) do not support switching the encoding.

@Ryuno-Ki Yes, iconv would work, of course. Windows users could pipe it through the builtin Out-File, too:

echo "<h1>Hello {{name}}</h1>" | out-file -encoding utf8 HelloWorld.html
Rich-Harris commented 7 years ago

Whew, would never have figured that out, thanks all. I wonder if perhaps the docs should just say 'create a HelloWorld.html file that looks like this' rather than getting into all that – as an OS X user I'd look at command and wonder what on earth was going on.

Lol Windows, always finding new and exciting ways to do things wrong!

mrkishi commented 7 years ago

To be fair, soon, most Windows dev environments will be closer to Linux than macOS, through WSL. 😛

But I agree with you, removing the echo mention would be cleaner, as opposed to adding a UTF-8 disclaimer for Windows users.

Rich-Harris commented 7 years ago

Have updated the guide, so I'll close this issue