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

not support [email protected] #59

Open
nnecec opened this issue Sep 29, 2018 · 23 comments
Open

not support [email protected] #59

nnecec opened this issue Sep 29, 2018 · 23 comments

Comments

@nnecec
Copy link

nnecec commented Sep 29, 2018

Throw error when update parcel to 1.10.
Look like typescript compile failure.
Maybe because [email protected] support babel@7, I don't know ..

@cyntler
Copy link

cyntler commented Oct 11, 2018

Exactly. This is happening. When I made the parcel-bundler downgrade to 1.9.4 everything works fine.

@mironal
Copy link

mironal commented Oct 13, 2018

You can use tsc -noEmit instead of parcel-plugin-typescript.

Because parcel-plugin-typescript is mainly used only for type check.

ex.

{
    "scripts": {
        "build": "parcel build src/index.ts --target node"
    }
}

to

{
    "scripts": {
        "build": "tsc - no Emit && parcel build src/index.ts --target node"
    }
}

@mnn
Copy link

mnn commented Oct 26, 2018

Yeah, it seems TypeScript files aren't being processed by tsc.

$ npx parcel build src/index.ts
🚨  SyntaxError: /xxx/src/index.ts: Unexpected token, expected ";" (7:5)

   5 | import * as fp from 'fp-ts';
   6 | 
>  7 | var a: string = '';
     |      ^

Versions:
[email protected]
[email protected]

@cruhl
Copy link

cruhl commented Nov 15, 2018

I'm having the same issue

@TkDodo
Copy link

TkDodo commented Nov 18, 2018

You can use tsc -noEmit instead of parcel-plugin-typescript.

As far as I know, absolute imports are not working with parcel if you are not using parcel-plugin-typescript, so I need that plugin to work. Unfortunately, I am having the same issue when upgrading to 1.10.3

@mmmeff
Copy link

mmmeff commented Nov 19, 2018

This is a really bad bug. First noticed it while learning Parcel on codesandbox, attributed it to the platform, started a new project locally and I'm still having issues compiling typescript files. Any typescript-specific syntax breaks the compiler. Both .ts and .tsx file extensions break parcel.

@joseluisq
Copy link

Any updates? I have the same issue:

  "parcel-bundler": "^1.10.3",
  "parcel-plugin-typescript": "^1.0.0"

@mitchellnemitz
Copy link

mitchellnemitz commented Nov 29, 2018

I solved this issue by abandoning this plugin and instead installing @babel/preset-typescript and babel-plugin-module-resolver with this bit of config in my .babelrc:

{
    "presets": [
        ...
        "@babel/preset-typescript"
    ],
    "plugins": [
        [
            "module-resolver", {
                "alias": { ... },
                "root": ["./same/as/tsconfig.json/baseUrl"],
                "extensions": [".js", ".jsx", ".ts", ".tsx"]
            }
        ]
    ]
}

@benpolinsky
Copy link

benpolinsky commented Jan 16, 2019

@mitchellnemitz this "works" but still doesn't report errors on build.

Edit: unless I am missing something, which could very well be the case :)

@quantuminformation
Copy link

same issue?

#13 (comment)

@mitchellnemitz
Copy link

@benpolinsky if you add "noEmit": true to your tsconfig.json you can just run tsc in parallel with your build to find any type errors. The point of using babel instead of typescript directly is just to speed up build and move type checking to more of a lint-type situation that can be run in parallel, which can be a good or bad thing depending on your goals and mentality.

@benpolinsky
Copy link

@mitchellnemitz Thanks for explaining the thinking behind the decision. From my perspective, it'd be great to have as part of Parcel's zero-config philosophy since it's pretty crucial to TypeScript. JSLint isn't essential to JS, but type checking is pretty essential to TypeScript - that's my line of thought anyhow.

@mitchellnemitz
Copy link

@benpolinsky Hrm, I actually agree. I'm just so used to solving my problems by piling on tooling and configuration that I almost forget what Parcel is supposed to be.

I'm going to take a pass at creating a Typescript plugin that compiles via Babel but runs type checking with tsc -- hopefully that approach will keep the builds fast while still reporting on type errors, and hopefully the plugin code itself will be minimal and I can pass most of the inevitable issues upstream 😛

@mitchellnemitz
Copy link

For what it's worth, you could just go with my approach combined in an npm script like so until I get an alternative plugin together: #59 (comment)

@benpolinsky
Copy link

Here's what I cobbled together the other day, seemed to work okay. Just building off the included TS Asset:

https://gist.github.com/benpolinsky/a968b18b82ae2805f742e3cc04cf9417

Basically using the examples from the TypeScript compiler API to list diagnostics but not emit the TypeScript. Then let parcel + Babel do their thing.

@quantuminformation
Copy link

My project was fine with webpack, can anyone advise how to fix parcel here:

https://github.com/QuantumInformation/youtube-space-invaders/tree/b

@mitchellnemitz
Copy link

@quantuminformation can you be more specific as to what error you're experiencing? Is it that your Typescript isn't compiling with this plugin? If so, try one of the solutions above involving Babel 7.x and tsc in an npm script. If it's something else, you should open an issue in the relevant repository.

@quantuminformation
Copy link

This is the error
screen shot 2019-01-24 at 14 38 46

ill try the above, i thought parcel was 0 config..

@mitchellnemitz
Copy link

If you're using Typescript, you're beyond the zero-config functionality of Parcel. It has out of the box support for JS / CSS / HTML and a few other things, but not TS. Set up Typescript through Babel and create an npm script as suggested above and you'll be off to the races again.

@quantuminformation
Copy link

dang, might go back to webpack.

@quantuminformation
Copy link

@mitchellnemitz what do I put in place of "alias": { ... },

@mitchellnemitz
Copy link

alias in the module resolver context is analogous to paths in tsconfig.json -- i.e. a list of path mapping entries from module names -> locations relative to your baseUrl. In Webpack this is resolve.alias.

See Module Resolution documentation for more details: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

Most people won't need the alias option, but it's useful to point out how it fits in for completeness.

uyhcire added a commit to uyhcire/tabliner that referenced this issue Jun 8, 2019
@rfgamaral
Copy link

(...) if you add "noEmit": true to your tsconfig.json you can just run tsc in parallel with your build to find any type errors.

I understand the reasoning behind this to implement type checking before building and making sure code is not emitted if there are errors.

The point of using babel instead of typescript directly is just to speed up build(...)

But I don't quite understand the need for this, especially when paired with this:

If you're using Typescript, you're beyond the zero-config functionality of Parcel. It has out of the box support for JS / CSS / HTML and a few other things, but not TS.

Which is not quite true!? I mean, Parcel has [partial] support for TypeScript out of the box, it just doesn't do type checking. But we can work around that issue with tsc, before running parcel.

So, what are the real advantages of moving to Babel instead of TypeScript for compilation besides "speed"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests