wking-io / elm-live

⚡ A flexible dev server for Elm. Live reload included.
https://elm-live.com
MIT License
1.05k stars 61 forks source link

sometimes exits or doesn't pick up changes when using vim #197

Open towc opened 5 years ago

towc commented 5 years ago

Possibly related to https://github.com/wking-io/elm-live/issues/97

elm-live version 4.0.0-rc.1 vim 8.1

Sometimes when saving src/Main.elm with vim, elm-live src/Main.elm might exit unexpectedly.

It's quite rare, and I couldn't link it to any specific context. I've tried

Sometimes it just doesn't see some updates, but doesn't quit, and will pick up the next change.

Other times it just stops watching. This might not be vim related. One way to reproduce is with a fresh elm.json, and running elm install elm/json, which will move it from indirect to direct dependencies. After that command, the already running elm-live will keep running, but won't pick up any changes

Here are some logs of failures, all with exit code 0:

elm-live:
  You’ve changed `src/Main.elm`. Rebuilding!

elm-live:

-- FILE NOT FOUND ---------------

I cannot find this file:

    src/Main.elm

Is there a typo?

Note: If you are just getting started, try working through the examples in the
official guide https://guide.elm-lang.org to get an idea of the kinds of things
that typically go in a src/Main.elm file.
$ elm-live src/Main.elm

elm-live:
  Server has been started! Server details below:
    - Website URL: http://localhost:8000
    - Serving files from: /home/user/exp/elm/random

elm-live:
  The build has succeeded.

elm-live:
  Watching the following files:
    - src/**/*.elm

elm-live:
  You’ve changed `src/Main.elm`. Rebuilding!

elm-live:

-- UNEXPECTED FILE EXTENSION ---------------

I can only compile Elm files (with a .elm extension) but you want me to compile:

    src/Main.elm

Is there a typo? Can the file extension be changed?
-- TYPE MISMATCH --------------- /home/user/exp/elm/random/src/Main.elm

The 1st pattern in this `case` causing a mismatch:

91|             ++ [ case model of
92|>                    Failure ->
93|                         text "I was unable to load your book."
94|
95|                     Loading ->
96|                         text "Loading..."
97|
98|                     Success fullText ->
99|                         pre [] [ text fullText ]

The first pattern is trying to match `Failure` values of type:

    ReqModel

But the expression between `case` and `of` is:

    Model

These can never match! Is the pattern the problem? Or is it the expression?

elm-live:
  You have a compiler error. No biggie, just read the error above and figure out what's up

elm-live:
  You’ve changed `src/Main.elm`. Rebuilding!

Error parsing result:  SyntaxError: Unexpected token
                                                      in JSON at position 339
    at JSON.parse (<anonymous>)
    at ChildProcess.<anonymous> (/home/user/.npm-global/lib/node_modules/elm-live/lib/src/build.js:110:33)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
{ build:
   { action: 'error',
     data:
      '{"type":"compile-errors","errors":[{"path":"/home/user/exp/elm/random/src/Main.elm","name":"Main","problems":[{"title":"UNFINISHED PARENTHESES","region":{"start":{"line":67,"column":3
1},"end":{"line":67,"column":31}},"message":["I was expecting to see a closing parentheses next, but I got stuck here:\\n\\n67|           ( (Tuple.first model\u000b))\\n
             ",{"bold":false,"underline":false,"color":"RED","string":"^"},"\\nTry adding a ",{"bold":false,"underline":false,"color":"yellow","string":")"}," to see if that helps?\\n\\n",{"
bold":false,"underline":true,"color":null,"string":"Note"},": I can get stuck when I run into keywords, operators, parentheses, or\\nbrackets unexpectedly. So there may be some earlier synta
x trouble (like extra\\nparenthesis or missing brackets) that is confusing me."]}]}]}' },
  cwd: '/home/user/exp/elm/random',
  dir: '/home/user/exp/elm/random',
  elm: 'elm',
  elmArgs: [ 'src/Main.elm' ],
  getAction: [Function: getAction],
  host: 'localhost',
  hot: false,
  log: [Function: bound consoleCall],
  open: false,
  port: 8000,
  proxyPrefix: false,
  proxyHost: false,
  pushstate: false,
  reload: true,
  server:
   { wss:
      WebSocketServer {
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _server: [Server],
        _removeListeners: [Function: removeListeners],
        clients: [Set],
        options: [Object] },
     sendMessage: [Function: sendMessage] },
  useServer: true,
  ssl: false,
  startPage: 'index.html',
  target: 'index.html',
  verbose: false }
$ elm-live src/Main.elm

elm-live:
  Server has been started! Server details below:
    - Website URL: http://localhost:8000
    - Serving files from: /home/user/exp/elm/random

elm-live:
  The build has succeeded.

elm-live:
  Watching the following files:
    - src/**/*.elm

elm-live:
  You’ve changed `src/Main.elm`. Rebuilding!

Error parsing result:  SyntaxError: Unexpected number in JSON at position 2
    at JSON.parse (<anonymous>)
    at ChildProcess.<anonymous> (/home/user/.npm-global/lib/node_modules/elm-live/lib/src/build.js:110:33)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
{ build:
   { action: 'error',
     data:
      '\n-- ERROR -----------------------------------------------------------------------\n\nI ran into something that bypassed the normal error reporting process! I\nextracted whatever info
rmation I could from the internal error:\n\n>   Error from `Main` should have been reported already.\n>   CallStack (from HasCallStack):\n>     error, called at builder/src/Build.hs:1233:29
in main:Build\n\nThese errors are usually pretty confusing, so start by asking around on one of\nforums listed at https://elm-lang.org/community to see if anyone can get you\nunstuck quickly
.\n\n-- REQUEST ---------------------------------------------------------------------\n\nIf you are feeling up to it, please try to get your code down to the smallest\nversion that still tri
ggers this message. Ideally in a single Main.elm and\nelm.json file.\n\nFrom there open a NEW issue at https://github.com/elm/compiler/issues with your\nreduced example pasted in directly. (
Not a link to a repo or gist!) Do not worry\nabout if someone else saw something similar. More examples is better!\n\nThis kind of error is usually tied up in larger architectural choices th
at are\nhard to change, so even when we have a couple good examples, it can take some\ntime to resolve in a solid way.elm: Error from `Main` should have been reported already.\nCallStack (fr
om HasCallStack):\n  error, called at builder/src/Build.hs:1233:29 in main:Build\n' },
  cwd: '/home/user/exp/elm/random',
  dir: '/home/user/exp/elm/random',
  elm: 'elm',
  elmArgs: [ 'src/Main.elm' ],
  getAction: [Function: getAction],
  host: 'localhost',
  hot: false,
  log: [Function: bound consoleCall],
  open: false,
  port: 8000,
  proxyPrefix: false,
  proxyHost: false,
  pushstate: false,
  reload: true,
  server:
   { wss:
      WebSocketServer {
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _server: [Server],
        _removeListeners: [Function: removeListeners],
        clients: [Set],
        options: [Object] },
     sendMessage: [Function: sendMessage] },
  useServer: true,
  ssl: false,
  startPage: 'index.html',
  target: 'index.html',
  verbose: false }
mb00t commented 4 years ago

:set backupcopy=yes or ~/.vimrc set backupcopy=yes

ccomb commented 2 years ago

:set backupcopy=yes or ~/.vimrc set backupcopy=yes

Thanks !! It's the solution, indeed, but it doesn't explain the problem. I had the same error with any live-reloading solution, and it was due to the elm file being rewritten by a vim plugin reformatting the source file at each save: The plugin uses a temporary file and during the short time the source file does not exist, elm-live thinks it is gone, then end up with an error (MODULE NOT FOUND). Just by adding this line in the .vimrc solves the issue.

There is a possible improvement for elm-live : add an option to delay the live-reload by an arbitrary duration, just to give a little more time for the vim plugin to reformat and save the file.