Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"--watch" options does not works. #8789

Closed
hg-pyun opened this issue Sep 30, 2018 · 12 comments
Closed

"--watch" options does not works. #8789

hg-pyun opened this issue Sep 30, 2018 · 12 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@hg-pyun
Copy link

hg-pyun commented Sep 30, 2018

Bug Report

Current Behavior
Setting up --watch options with a Babel and modifying a file should automatically be compiled. But now I don't think I can automatically compile.

Input Code

Expected behavior/code
Automatically compiles when the file that Babel is watching is modified.

Babel Configuration (.babelrc, package.json, cli command)
.babelrc

{
  "presets": [
    "@babel/env",
    "@babel/preset-typescript"
  ],
  "plugins": [
    ["@babel/plugin-transform-modules-umd", {
      "globals": {
        "iterize": "Iterize"
      },
      "exactGlobals": true
    }]
  ],
  "env": {
    "production": {
      "presets": [
        "minify"
      ]
    }
  }
}

package.json

{
  ...
  "devDependencies": {
    "@babel/cli": "^7.1.2",
    "@babel/core": "^7.1.2",
    "@babel/plugin-transform-modules-umd": "^7.1.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-typescript": "^7.1.0",
    "babel-preset-minify": "^0.5.0",
    "cross-env": "^5.2.0"
  },
  "scripts": {
    "dev": "babel ./src/index.ts --watch -o ./lib/iterize.dev.js"
  }
}

Environment

  • Babel version(s): 7.1.2
  • Node/npm version: 8.11.4
  • OS: OSX 10.13.6
  • How you are using Babel: cli
@babel-bot
Copy link
Collaborator

Hey @hg-pyun! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@idahogurl
Copy link

I am having the same issue.

package.json

{
  "name": "scripts",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "cheerio": "^1.0.0-rc.2",
    "good": "^8.1.2",
    "he": "^1.2.0",
    "moment": "^2.24.0",
    "request": "^2.88.0",
    "request-promise-native": "^1.0.7"
  },
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.3.4",
    "@babel/preset-env": "^7.3.4"
  },
  "scripts": {
    "build": "yarn babel ./index.js --out-file index.compiled.js",
    "dev": "nodemon index.compiled.js"
  }
}

.babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ]
}

@suginoki45
Copy link

Hi! Thank you for the great tool!
I also report the same issue as it occurs.

Environment

  • macOS 10.14 Mojave
  • Node v10.14.2
  • npm v6.9.0

package.json

{
  "name": "scripts",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "config": {
    "paths": "./file/to/path"
  },
  "scripts": {
    "watch:babel": "babel $npm_package_config_paths/src/js/bundle.js --watch --out-dir $npm_package_config_paths/dist/js"
  },
  "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.4",
    "@babel/preset-env": "^7.4.4"
  }
}

.babelrc

{
  "presets": ["@babel/preset-env"]
}

@alexisab
Copy link

alexisab commented Jul 1, 2019

Same problem :

{
    "name": "mypackage",
    "version": "1.0.0",
    "description": "",
    "main": "lib/index.js",
    "private": false,
    "files": [
        "/lib"
    ],
    "scripts": {
        "watch": "yarn transpile --watch",
        "transpile": "babel src -d lib",
        "clean": "rm -rf ./lib",
        "lint": "eslint src",
        "test": "mocha src/index.test.js"
    },
    "dependencies": {
        "core-js": "^3.1.4",
        "invariant": "^2.2.4",
        "regenerator-runtime": "^0.13.2"
    },
    "devDependencies": {
        "@babel/cli": "^7.4.4",
        "@babel/core": "^7.4.5",
        "@babel/preset-env": "^7.4.5",
        "chai": "^4.2.0",
        "eslint": "^6.0.1",
        "mocha": "^6.1.4"
    },
    "peerDependencies": {
        "koa": "^2.7.0",
        "pino": "^5.12.6"
    },
    "babel": {
        "presets": [
            "@babel/preset-env"
        ]
    }
}

yarn transpile works , but yarn watch doesn't transpile src on updates

@hg-pyun
Copy link
Author

hg-pyun commented Jul 2, 2019

@hzoo Please, check this issue :D

@loganfsmyth
Copy link
Member

Are folks here running these scripts in Docker or in a virtual machine or anything like that?

@hg-pyun
Copy link
Author

hg-pyun commented Jul 3, 2019

In my case, running on OSX 10.13.6

@alexisab
Copy link

alexisab commented Jul 3, 2019

In fact it seems to work but it doesn't log anything in the console to say that the code have been re-compiled

@eprikazc
Copy link

eprikazc commented Jul 31, 2019

For me, it does seem to work when running code on one partition, but does not work on another partition.
I reproduced it also with simple chokidar command, like:

./node_modules/.bin/chokidar script.jsx -c "echo hello"

So it seems to be some lower level thing related to specific partition/file system, unrelated to babel.
As a workaround, I managed to get babel working through chokidar using polling (-p option):

./node_modules/.bin/chokidar -p script.jsx -c './node_modules/.bin/babel script.jsx -o script.js'

@jasonmcaffee
Copy link

I encountered this issue with typescript. Babel will watch js files by default, but not .ts files.
To change this, provide the --extensions option to babel, along with the watch:

"build-watch": "babel src --out-dir build --source-maps --watch --extensions '.ts,.js'",

I'm using versions:

"devDependencies": {
    "@babel/cli": "^7.6.2",
    "@babel/core": "^7.6.2",
    "@babel/preset-typescript": "^7.6.0",
...
}

Hope that helps!

@JLHwung
Copy link
Contributor

JLHwung commented Oct 23, 2019

@jasonmcaffee Thank you for the report. The issue you reported will be fixed by #10283.

@JLHwung
Copy link
Contributor

JLHwung commented Jul 27, 2021

@hg-pyun Thanks for the reproduction repo. The issue you mentioned has been fixed in #10283.

If you hit here from search engines, please open a new issue with reproducing repo. Thanks!

@JLHwung JLHwung closed this as completed Jul 27, 2021
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

9 participants