Comments (4)
I'm guessing this is the right way to use this:
import KJUR, { b64toBA, b64utob64 } from 'jsrsasign';
Feel free to close the issue if you don't want to handle both.
from esbuild.
It's possible that this was fixed earlier. I'm guessing the fix was adding support for CommonJS default exports via __esModule
in #17.
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 --bundle
and then executed using node, all three of these output the same thing: [Function (anonymous)] [Function: b64toBA] [Function: b64utob64]
.
from esbuild.
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:
SyntaxError: The requested module 'pkg' does not provide an export named 'proto'
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 proto
to be accessible as a named export but it won't. The only way to use its types and runtime methods is:
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;
from esbuild.
@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/.
// proto // typescript finds it but node will fail on runtime
Keep in mind that you need --platform=node
when building for node. In this case esbuild generates annotations for node so node's syntactic CommonJS analyzer can find the re-exported export names: #2486.
from esbuild.
Related Issues (20)
- Bug: Handling dynamic imports
- Bug: Handling dynamic imports HOT 1
- directives doesn't have mappings in source map HOT 1
- Support for aix ppc64 BE HOT 31
- Panic when transforming optional chaining with `define` HOT 1
- Leaky timeout in Deno with `wasm.js` and `esbuild.build` HOT 2
- Sourcemap paths being appended when composing sourcemaps HOT 2
- Feature request: treeshaking of enums when declaration merging is present HOT 2
- Can we target the generated css file (generated from css module imports) HOT 3
- Dynamic Import JSON not working HOT 2
- After the build is completed, the esbuild process does not exit HOT 6
- ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor HOT 2
- Classes with iterators are not tree-shaken HOT 1
- When using iife format, the `module` and `exports` variables conflict with the code of other compilation tools. HOT 7
- Question: Build for browser with external modules in a folder? HOT 2
- I'm puzzled about the empty contents of on-load-results. HOT 2
- Can esbuild bundle in fetch call responses? HOT 2
- Esbuild-wasm in NextJs Context (Client) HOT 8
- Load separate builds based on the environment HOT 4
- Inline values which are used only once HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esbuild.