-
-
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
Directive usage for libraries #9050
Comments
With RSC getting traction, doing this automatically might be a good idea. Would work similar to the existing shebang handling that also extract A manual solution/workaround that produces correct sourcemaps would be adding an optimizer plugin: import {Optimizer} from '@parcel/plugin';
import {blobToBuffer} from '@parcel/utils';
import SourceMap from '@parcel/source-map';
export default new Optimizer({
async optimize({contents, map, options}) {
let correctMap;
if (map != null) {
correctMap = new SourceMap(options.projectRoot);
correctMap.addSourceMap(map, 1); // 1 = offset lines by 1
}
return {
contents: `"use client";\n` + (await blobToBuffer(contents)).toString(),
map: correctMap,
};
},
}); and then {
"extends": "@parcel/config-default",
"optimizers": {
"*.{js,mjs,cjs}": ["...", "that-new-optimizer"]
}
} |
I appreciate that pointer. Tried it locally with: "devDependencies": {
"@parcel/config-default": "^2.9.0",
"@parcel/core": "^2.9.0",
"@parcel/packager-ts": "^2.9.0",
"@parcel/plugin": "^2.9.0",
"@parcel/source-map": "^2.1.1",
"@parcel/transformer-typescript-types": "^2.9.0",
"@parcel/utils": "^2.9.0",
"parcel": "^2.9.0", I hit a snag using import/export syntax. Even if I used a const { Optimizer } = require("@parcel/plugin");
const { default: SourceMap } = require("@parcel/source-map/dist/node.js");
const { blobToBuffer } = require("@parcel/utils");
module.exports = new Optimizer({
async optimize({ contents, map, options }) {
let correctMap;
if (map != null) {
correctMap = new SourceMap(options.projectRoot);
correctMap.addSourceMap(map, 2); // Offset lines by 2
}
return {
contents: `"use client";\n\n` + (await blobToBuffer(contents)).toString(),
map: correctMap,
};
},
}); Seems to work well enough though 👍🏼 |
Looks like it would have to be this with mjs: import utils from "@parcel/utils";
import SourceMap from "@parcel/source-map";
new SourceMap.default()
utils.blobToBuffer() So we'll have to look into publishing ESM versions of the packages... |
+1, I just ran into that @parcel/fs doesn't have an ESM export
|
Is there any update regarding this. I'm facing same issue with a UI library in |
I'm hitting an issue where I see
I've followed the examples above but am still getting this error? |
@sandrahoang686 @ar124officialwd Put out our workaround as a plugin you can try. |
Related issue: bvaughn/react-error-boundary#143
I'm currently using ParcelJS to build several React component libraries, including react-error-boundary. The main entry point for this library,
index.ts
, declares a"use client"
directive:In the bundled output for this library though, the directive has been moved near the end of the file (as can be seen here).
I'm unaware of any way to instruct Parcel to preserve the location of the directive.
I've considered the following:
bundle-text
syntax to import the built module as text (but I don't know how to make this work with a TypeScript module)The text was updated successfully, but these errors were encountered: