-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Named namespace and function import doesn't work. #24
Comments
I'm guessing this is the right way to use this:
Feel free to close the issue if you don't want to handle both. |
It's possible that this was fixed earlier. I'm guessing the fix was adding support for CommonJS default exports via I'm going to close this since it looks like this is working fine now: import KJUR from 'jsrsasign';
import { b64toBA, b64utob64 } from 'jsrsasign';
console.log(KJUR.crypto.DSA, b64toBA, b64utob64); import { KJUR, b64toBA, b64utob64 } from 'jsrsasign';
console.log(KJUR.crypto.DSA, b64toBA, b64utob64); import KJUR, { b64toBA, b64utob64 } from 'jsrsasign';
console.log(KJUR.crypto.DSA, b64toBA, b64utob64); When bundled with esbuild using |
I've run into a situation where re-exported namespaces are not bundled properly as named exports when using barrel files and export star syntax. When doing this: import {
namedPropFromB,
proto
} from "pkg"; I'd get the following on node runtime: It will build and generate valid DTS about the exported proto NS. Original pkg exports are as follows: index.js import A from './A'
export * from '../proto'
export * from './B'
export default A Proto is generated by pbjs from protobufjs, not to confuse with pbjs also from @evanw: yarn pbjs -t static-module -w commonjs -o ./Proto/index.js ./Proto/Proto.proto;
yarn pbts -o ./Proto/index.d.ts ./Proto/index.js; ...
// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
$root.proto = (function() {
/**
* Namespace proto.
* @exports proto
* @namespace
*/
var proto = {};
proto.Something = (function() {
...
}
return proto;
})();
module.exports = $root; esbuild bundle: ...
Object.defineProperty(exports, "__esModule", { value: true });
const A_1 = __importDefault(require("./A"));
__exportStar(require("./B"), exports);
__exportStar(require("../Proto"), exports);
exports.default = A_1.default; I'd expect import {
namedPropFromB,
// proto // typescript finds it but node will fail on runtime
} from "pkg";
import * as pkg from "pkg";
const sample = pkg.proto.Something.Method(value) as pkg.proto.Something.ISomething; |
@gabrielalmeida You should file a new issue if you believe you have found a bug with esbuild. It would also be helpful to have a self-contained reproduction on https://esbuild.github.io/try/.
Keep in mind that you need |
This works:
This doesn't:
KJUR
is a namespace, while the others are functions or classes.Webpack handles this as expected.
The text was updated successfully, but these errors were encountered: