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

Major: use swc-loader for TypeScript compilation #777

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Conversation

styfle
Copy link
Member

@styfle styfle commented Sep 17, 2021

This is a major change since swc doesn't perform type checking, only compilation of TS to JS

TODO: remove transpileOnly flag since it is always true now

@styfle styfle changed the title Use swc loader for typescript compilation Use swc-loader for typescript compilation Sep 17, 2021
@styfle styfle changed the title Use swc-loader for typescript compilation Major: use swc-loader for TypeScript compilation Sep 17, 2021
@styfle
Copy link
Member Author

styfle commented Sep 17, 2021

@guybedford @sokra @kdy1 @huozhi Any thoughts on how to solve this one?

The module.exports = require("shebang-loader") is converted to module.exports = eval("require")("shebang-loader").
But I would expect the contents of the shebang-loader package instead.

Fixed that part in c68542c.

Now the JS integration tests pass but the TS ones fail with the following:

    Module build failed (from ./dist/ncc/loaders/swc-loader.js):
    Error: Can not load bindings
    Installed packages: [core-darwin-x64]

@kdy1
Copy link
Member

kdy1 commented Sep 18, 2021

It seems like node failed to resolve @swc/core-darwin-x64 from ./dist/ncc/loaders/swc-loader.js.

But I'm not sure about the reason, as I found yarn install in the CI script.

keepClassNames: true,
target: compilerOptions.target && compilerOptions.target.toLowerCase() || 'es2021',
paths: compilerOptions.paths,
baseUrl: compilerOptions.baseUrl,
Copy link
Member Author

@styfle styfle Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdy1 The paths and baseUrl tests are failing with:

panicked at 'failed to get current directory: Error { kind: Unsupported, message: "operation not supported on this platform" }', /home/runner/work/swc/swc/ecmascript/transforms/module/src/path.rs:81:56

Stack:

Error: 
    at u.exports.__wbg_new_59cb74e423758ede (dist/ncc/loaders/swc-loader.js.cache.js:1:2692)
    at null.<anonymous> (wasm://wasm/04480186:0:15193164)
    at null.<anonymous> (wasm://wasm/04480186:0:16752724)
    at null.<anonymous> (wasm://wasm/04480186:0:16566604)
    at null.<anonymous> (wasm://wasm/04480186:0:16677644)
    at null.<anonymous> (wasm://wasm/04480186:0:16749249)
    at null.<anonymous> (wasm://wasm/04480186:0:16736138)
    at null.<anonymous> (wasm://wasm/04480186:0:16687572)
    at null.<anonymous> (wasm://wasm/04480186:0:5322716)
    at null.<anonymous> (wasm://wasm/04480186:0:15233495)

Copy link
Member Author

@styfle styfle Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdy1 The new @swc/wasm no longer panics, but it still fails with very strange behavior.

Input:

https://github.com/vercel/ncc/blob/main/test/unit/tsconfig-paths/input.ts

import module from "@module";

console.log(module);

Output:

/******/ 	var __webpack_modules__ = ({

/***/ 105:
/***/ ((module) => {

module.exports = eval("require")("../../../../../../../../.././module");


/***/ })

/******/ 	});

Runtime result:

Error: Cannot find module '../../../../../../../../.././module'

@harisvsulaiman
Copy link

Now that swc is extensively used at vercel, swc support in ncc would be hugely beneficial.

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

Successfully merging this pull request may close these issues.

None yet

3 participants