-
Notifications
You must be signed in to change notification settings - Fork 1
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
cannot directly use Node platform implementation #1
Comments
Yeah the problem is probably coming from the fact I need to import a node native module for the node implementation, which is currently done using a CommonJS file ( This package right now was mostly a proof of concept. I'll see what I can do. Any PR welcome to improve the situation. |
ESM in node will have an |
Yeah, admittedly I was using this package as a playground to figure out a good way to publish both ESM and CJS, so that the ESM can be used directly in the browser without any bundlers or transpilers. |
You can still provide that kind of build, but the "main" in package.json needs to have node compatibility as a priority - ie, CJS ES5. |
100% agreed, hence why there is no |
Thanks guys: in the interim I have it working (so to spare others from going down the rollup rabbit hole and waking up in babylon) I'm more than willing to setup babel and rollup, I'll make the PR tomorrow.
|
Yeah I ended up extracting this from a bigger library I'm working on, so I'll keep supporting it for now. I need to update it to the latest changes in the spec that happened in the past few days. No major changes, mostly around how host jobs are processed. I'm also not happy right now with the way the internal scheduling works. |
I just pushed a commit adding support for a CommonJS main. I also changed the way I'm loading I also took the opportunity to add support for the experimental modules support of node 12. Please let me know if this solves your issue, and I'll create a new release of the shim. |
I extracted the You shouldn't need any more CommonJS workarounds and hopefully the module output is compatible with babel. |
Woooooooo will give it a shot and get back to you.
…On Fri, 03 May 2019, 21:44 Mathieu Hofman, ***@***.***> wrote:
I extracted the weak-napi bindings into an external package
***@***.***/weak-napi-native> so now the
module output should be 100% isomorphic ESM.
You shouldn't need any more CommonJS workarounds and hopefully the module
output is compatible with babel.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABAXP2BBKCOZD3CQTACVAETPTSIYFANCNFSM4HJ74WBQ>
.
|
Gave it a test, it now builds in rollup without any special settings, other than having the commonjs included where I didn't previously need it. import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import sourcemaps from 'rollup-plugin-sourcemaps';
import pkg from './package.json';
const BABEL_CONFIG = babel({
babelrc: true,
exclude: 'node_modules/**',
/* no special includes needed */
runtimeHelpers: true //transform-runtime plugin
}),
COMMONJS_CONFIG = commonjs({ /* no settings needed */ }),
RESOLVE_CONFIG = resolve({
extensions: [ '.js', '.es', '.mjs', '.json' ]
}),
DEPENDENCIES = Object.keys(pkg.dependencies);
export default [{
input: [...],
external: DEPENDENCIES,
output: [
{ dir: 'dist/common', format: 'cjs'},
{ dir: 'dist/module', format: 'esm'}
],
plugins: [
RESOLVE_CONFIG,
COMMONJS_CONFIG, // this is still needed
sourcemaps(),
BABEL_CONFIG
]
}]; |
nvm, fixed it, forgot since I'm using the Node binding directly that I need to manually add the dependency to the external import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import sourcemaps from 'rollup-plugin-sourcemaps';
import pkg from './package.json';
const BABEL_CONFIG = babel({
babelrc: true,
exclude: 'node_modules/**',
runtimeHelpers: true //transform-runtime plugin
}),
RESOLVE_CONFIG = resolve({
extensions: [ '.js', '.es', '.mjs', '.json' ]
}),
DEPENDENCIES = Object.keys(pkg.dependencies);
DEPENDENCIES.push('tc39-weakrefs-shim/module/node');
export default [{
input: [...],
external: DEPENDENCIES,
output: [
{ dir: 'dist/common', format: 'cjs'},
{ dir: 'dist/module', format: 'esm'}
],
plugins: [
RESOLVE_CONFIG,
sourcemaps(),
BABEL_CONFIG
]
}]; this is about as standard as you can get. so I would say this issue can be closed, and if you are happy then publish a new release (I've built from master) |
EDIT: My bad, rollup doesn't actually care about file types. Any suggestion on how to improve the deep linking story? You should be able to use |
|
Renaming everything would be an extensive change to my projects right now, which I'd rather avoid. Also, |
Version 0.0.2 has been published. |
Just for good measure - confirming it works with |
Env:
in the appropriate class in the library I have:
Which then gets compiled bundled with babel7 and rollup.
Initially, I excluded the shim from babel transpilation and rollup bundling.
rollup.config.js snippet
which allowed rollup to bundle successfully, however now the application is throwing Syntax Errors
I think it would be best to provide a commonjs compatible export, or how else would this work? rollup can handle dynamic imports and code splitting now so if you want esm and cjs support with dynamic imports in the bundle then I can probably do that setup quickly since thats how I run my libs.
The text was updated successfully, but these errors were encountered: