-
Notifications
You must be signed in to change notification settings - Fork 786
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
[FeatureRequest] esm release #2079
Comments
Great @loynoir! Would you be willing to come up with a PR (and an explanation on how to test it)? |
Got esm release without rollup plugin. 😀 |
@loynoir oh, you already used the cond. exports. :-) |
but should we really use .mjs file extension? See also here: https://developer.mozilla.org/de/docs/Web/JavaScript/Guide/Modules#aside_%E2%80%94_.mjs_versus_.js |
I think $ node --experimental-repl-await
Welcome to Node.js v14.16.0.
Type ".help" for more information.
> require('.')
'cjs'
> await import('./x.mjs')
[Module: null prototype] { default: 'esm' }
> await import('./x.esm.js')
(node:1726626) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. add that $ node --experimental-repl-await
Welcome to Node.js v14.16.0.
Type ".help" for more information.
> await import('./x.esm.js')
[Module: null prototype] { default: 'esm' }
> await import('./x.mjs')
[Module: null prototype] { default: 'esm' }
> require('.')
Uncaught:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: |
Work:
|
As mention above, As it is dual module, and for backward compact, I wrote default condition as umd over esm. So, it should be 100% backward compact if using So, it should be 100% backward compact if webservers access esprima in a So, it should be tree shakable if using |
maybe ".js" only works when you set "type=module " in package.json |
To support // loading from `esprima.js`
const { parse } = require('esprima')
// Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
// 0% backward compact.
// loading from `esprima.esm.js`, tree shakable
import { parse } from 'esprima'
// OK So, I prefer // loading from `esprima.js`
const { parse } = require('esprima')
// OK, 100% backward compact
// loading from `esprima.mjs`, tree shakable
import { parse } from 'esprima'
// also OK |
i think .cjs would work for the old files if you use type=module. |
but .mjs for esm modules would still be better than no esm version :-) |
maybe we should also include .d.ts type infos in the esm version? |
Tried to let tsc generate src/tokenizer.ts:122:5 - error TS4053: Return type of public method from exported class has or is using name 'Error' from external module "<foobar>/esprima/src/error-handler" but cannot be named.
122 errors() {
~~~~~~
Found 1 error. |
I don't think that would be better... they would always be older.... |
TS4053 fixed. Now there is Try it at, npm install loynoir/esprima add |
We tried to use your package, but the dist folder is empty |
@lschirmbrand Yes.
But, I add If your npm not support that way, you might clone my fork, and manually run npm run test |
@loynoir but we used
this is a npm package? (or am I wrong?) |
@lschirmbrand If you are using
npm install loynoir/esprima
// npm expand it to
npm install https://github.com/loynoir/esprima
git clone https://github.com/loynoir/esprima
cd esprima
npm install
npm run test |
@lschirmbrand Could you show some toolchain version? node --version
npm --version |
@lschirmbrand |
@loynoir |
@jogibear9988 $ git clone https://github.com/jquery/esprima
$ cd esprima
$ yarn install && echo OK
OK
$ yarn test
> [email protected] lint-code
> eslint src/*.ts
esprima/src/assert.ts
0:0 error Parsing error: Not implemented
esprima/src/character.ts
0:0 error Parsing error: Not implemented
esprima/src/comment-handler.ts
0:0 error Parsing error: Not implemented
esprima/src/error-handler.ts
0:0 error Parsing error: Not implemented
So, I don't know the reason, but package manager seems matter in this case. Maybe related to another thing I found. Forgot to fill an issue. |
@loynoir |
@jogibear9988 Oh, that's good to hear too. 👏 |
Will esprima release support es module?
Something like tree-shaking-able
dist/esprima.mjs
.ramda/ramda
publish cjs and esm at same time, its package.json might helpful.Last, appreciate a lot for this great library. 😀
The text was updated successfully, but these errors were encountered: