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)
- Get metafile info from a `watch()` rebuild HOT 2
- removes the backslash "\" when minify option is false HOT 8
- [Sourcemap] Private properties don't get sourcemapped correctly HOT 3
- ENV Secrets accessible from js code in a React + Rails APP. HOT 7
- [Feature] Ability to save charts from Bundle Size Analyzer as svg files
- TypeError: Cannot set property X of #<Object> which has only a getter HOT 2
- Line limit option (lineLimit) breaks code HOT 3
- `esnext` target doesn't transform using declarations but `es2022` does HOT 2
- Default exports not handled correctly when external=true and module is dynamically imported (node16)
- Is there a problem here? does this make sense? HOT 4
- Glob-style imports with partial directory name substitutions
- Option to assign default export to globalName for iife format HOT 3
- Running esbuild under npm explore no longer works HOT 1
- esbuild not work well with package.json has "exports:{"./*": "./*"}" HOT 2
- Allow destructuring for all target environments HOT 1
- re-create package.json with only externalized dependencies
- SyntaxError: The requested module X does not provide an export named Y since code modification HOT 1
- Cross-Platform Development Problem HOT 6
- CSS media query range syntax not downleveled
- Object rest and function scope HOT 4
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.