-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
v2: "Got unexpected null" when building TypeScript project #3690
Comments
Very likely the same bug as #3640. (Also using |
Thanks. I removed the sentry package for now, and updated the parcel-v2 branch with the removal. I am now hitting another error:
I don't know why it thinks that GfxBindings is not exported, when it clearly is. Is there a way to turn scope hoisting off for now? All I could find was this, which implies it should be off by default: https://github.com/parcel-bundler/parcel/blob/v2/packages/core/parcel-bundler/src/Bundler.js#L110-L111 |
(Even in the v2 branch, |
Thank you, I've disabled scope hoisting for now, which seems to have solved my problem. If you intend to look into the scope hoisting issues, please let me know if you need any help setting up the repo for a repro case. |
Actually, the output from typescript for export enum _T { Buffer, Texture, ColorAttachment, DepthStencilAttachment, Sampler, Program, Bindings, InputLayout, InputState, RenderPipeline };
interface GfxResourceBase { ResourceName?: string, ResourceUniqueId: number };
export interface GfxBuffer extends GfxResourceBase { _T: _T.Buffer };
export interface GfxTexture extends GfxResourceBase { _T: _T.Texture };
// ...
export type GfxResource =
GfxBuffer | GfxTexture | GfxColorAttachment | GfxDepthStencilAttachment | GfxSampler | GfxProgram | GfxBindings | GfxInputLayout | GfxInputState | GfxRenderPipeline; is export var _T;
(function (_T) {
_T[_T["Buffer"] = 0] = "Buffer";
_T[_T["Texture"] = 1] = "Texture";
// ...
})(_T || (_T = {}));
I'm kind of surprised that works without scope hoisting. How does TS know that another modules exports aren't really named exports but an object property in a named export TS playground, and Babel doesn't support this at all? REPL |
Interfaces are not a thing that have any runtime equivalent. They only exist in the typesystem. |
I see, but Typescript can't know that import { GfxDevice, GfxBufferUsage, GfxBuffer, GfxInputState, GfxFormat, GfxInputLayout, GfxProgram, GfxBindingLayoutDescriptor, GfxRenderPass, GfxBindings, GfxHostAccessPass, GfxVertexAttributeFrequency } from '../gfx/platform/GfxPlatform'; need to be completely removed with the Flow has |
They aren't needed at runtime. But the issue here is that Typescript doesn't know if an import is importing a "real" value or an interface (where the export won't exist at runtime). |
It will know, because an interface is never used except as a type annotation. You cannot declare functions on interfaces, nor construct them with GfxBindings should never appear in any transpiled module's output. Why the scope hoisting code is seeing it is the real issue here. |
Parcel could work around this Typescript problem by removing unused import specifiers (e.g. But generally, this (the Typescript output) is a violation of the ESM module spec ( |
Is the TypeScript output here generating an import for GfxBindings? That sounds like a TSC bug if it is. |
Yes (which is understandable because every file is transpiled individually and TS can't know if GfxBindings will exist at runtime. They'd have to remove an import if it's only used as a type annotation.) |
I'll have to investigate later. If you can send me the TSC output or tell me where to find it, that would be a huge help. Not quite sure how to navigate the Parcel cache myself. |
TSC should be doing this already. See the example I posted above: https://www.typescriptlang.org/play/index.html#code/JYWwDg9gTgLgBAbzgYQuCA7AphmAaOAJSwEMBjGAOQgBMsBBKKEgTzgF84AzKNOAciikK-ANwAocWQA2JAM5y4AMQgQ4WAB4wcNRanTZcicXFNwwAVwBG04GTgQrAKywU5ALiLCqtBk1YA2gC6cAC8cMES7OJAA |
Interesting, now the question is where the import isn't removed. |
does babel do the same thing (remove type imports)? v2 uses babel to compile typescript by default, not tsc. |
@devongovett his parcelrc: {
"extends": "@parcel/config-default",
"transforms": {
"*.ts": [ "@parcel/transformer-typescript-tsc", "@parcel/transformer-js" ]
}
} |
Yes, Babel's TypeScript support chokes on my project currently, so I cannot use it. |
Did anyone find a workaround for this error ? |
… the messages, blocked by parcel-bundler/parcel#3690
I was able to solve this issue by removing two lines: (There are additional build errors that appeared after I solved this one, but they appear unrelated - I might be able to fully peel the onion if I have a bit more time). The problem is that if you re-export types, you thwart typescript's ability to do "import elision" (i.e. detect whether an imported type is just used as a type (and can be removed by the transpiler) or not (and therefore should remain). This is a problem if you're compiling using Assuming that parcel2 will be sticking with |
Ah, thank you, that makes sense. Re-exporting a type is a grammar position where types are allowed and can't be elided. |
@DeMoorJasper - I think you can close this because we found the root cause was by-design behavior. I opened #4240 to track the idea of providing more helpful error messages in this case. |
I deleted the .parcel-cache folder and it works! |
You will also get this error in an isolated module, ie one that does neither import nor export anything |
🐛 bug report
When trying to upgrade my project to Parcel V2, I got the error message:
🎛 Configuration (.babelrc, package.json, cli command)
The project is available here: https://github.com/magcius/noclip.website/tree/parcel-v2
🌍 Your Environment
The text was updated successfully, but these errors were encountered: