Main inside package.json is referencing to es6 modules
See original GitHub issueBug Main inside package.json is referencing to es6 modules
What MDC-Web Version are you using?
This happens with all components which have different versions, for instance the TextField is in version 0.3.1
What are the steps to reproduce the bug?
- Create a project with
npm init
- Install the TextField component
npm i --save @material/textfield
- Configure rollup or webpack to bundle the project and set babel to exclude ‘node_modules/**’
- Somewhere in your project use the textfield:
import * as textfield from '@material/textfield';
mdcComponent = new textfield.MDCTextfield(element)
- Check that the bundled app has the TextField component written in es6
- Go to
node_modules/@material/textfield
- Change “main” from “index.js” to “dist/mdc.textfield.min.js”
- Create the bundle again, note that this time it will not find the module
- Change “main” back to “index.js”
- Stop excluding ‘node_modules/**’ in the babel configuration
- Should work fine this time
What is the expected behavior?
The “main” property inside the package.json should reference to the transpiled and bundled module instead of the es6 version so developers don’t have to transpile it in order to avoid incompatibilities. For example the TextField component should be pointing to dist/mdc.textfield.min.js instead of index.js.
There’s actually another problem because the dist versions are exporting the utilities differently. The following snippet should work equally in the original and the minified/transpiled version:
import * as textfield from '@material/textfield';
mdcComponent = new textfield.MDCTextfield(element)
but using the later i get the following error: ‘MDCTextfield’ is not exported by ‘node_modules@material\textfield\dist\mdc.textfield.min.js’
What is the actual behavior?
The “main” is pointing to index.js which contains the es6 module, and if I don’t transpile it some things won’t work, for example I cannot use Uglify.
(uglify plugin) Error transforming bundle with ‘uglify’ plugin: Unexpected token: name (MDCFoundation)
That’s because it finds MDCFoundation defined as a class.
Any other information you believe would be useful?
There is a proposal to specify two entry points or main references inside package.json:
...
"main": "dist/app.min.js",
"jsnext:main": "index.js",
...
For more information refer to this issue: https://github.com/jsforum/jsforum/issues/5
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:15 (3 by maintainers)
Top GitHub Comments
We’ve changed our packages’
main
properties to point todist
resources in #3245. This will be available in 0.41.0.Thanks everyone for the input and sorry for the delay. (Also thanks @moog16 for starting the ball rolling and doing some testing for the PR.)
Is there any movement on this? I can open a PR if there is consensus on what should happen.