简体   繁体   中英

Babel creates output directory but doesn't transpile any files

I am trying to transpile a project that uses ES6 syntax and TypeScript. I have a directory structure like this:

├── .babelrc
├── src
    ├── index.ts
    └── pitching
        ├── pitching.test.ts
        └── pitching.ts

I would like to compile everything in src and output into dist/ . I have tried many variations of the following command (specified in the "build" script in package.json ):

babel ./src -d ./dist

But I always get the following output:

$ babel ./src -d ./dist
Successfully compiled 0 files with Babel (13ms).
Done in 0.32s

The result is an empty dist/ directory in my project root. I tried compiling to a single file instead of a directory, which did create a compiled file, but all the module paths referenced in the code were messed up because they were relative to the src directory. I only mention this because to me it indicates that my babel setup is correct, though maybe I am wrong about that too.

My question is, why are my files not being transpiled, or how can I troubleshoot? The command doesn't give me any helpful output, even when I add the {"debug": true} to the presets in my .babelrc .

For reference, here are the babel packages and versions I am using:

"devDependencies": {
    "@babel/cli": "^7.10.3",
    "@babel/core": "^7.10.3",
    "@babel/preset-env": "^7.10.3",
    "@babel/preset-typescript": "^7.10.1",
    "@types/jest": "^26.0.3",
    "jest": "^26.1.0"
}

and here is my .babelrc

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

Try adding ts to the extensions:

babel --extensions '.ts' ./src -d ./dist

babel/preset-typescript needs an extra argument to transpile as expected. See documentation here .

In my case I was already using the --extensions '.ts' flag, but still getting "Successfully compiled 0 files". I'm not sure what else is different between our setups, but for me what solved it was the solution outlined here . Once I removed the wrapping quotes around the .ts it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM