cvent / json-schema-deref-sync

Synchronous json schema dereference utility
http://bojand.github.io/json-schema-deref-sync
MIT License
35 stars 24 forks source link

Primary entry point ("main") is not ES5 and causes minifier to crash #12

Open angelikatyborska opened 6 years ago

angelikatyborska commented 6 years ago

1) What version of the module is the issue happening on? Does the issue happen on latest version? v0.4.0 from npm package registry and master branch from GitHub.

2) What platform and Node.js version? (For example Node.js 0.12 on Mac OS X) Node v8.9.0 on macOS 10.12.6

3) Sample source code or steps to reproduce

  1. Set up a new project in ES6 that uses Babel and a minifier. For example using create-react-app.
    $ create-react-app my-app
    $ cd my-app && npm install

Try to run build the project without this library. See the build successfully end:

$ npm run build

> my-app@0.1.0 build /Users/angelika/my-app
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  35.72 KB  build/static/js/main.ee7b2412.js
  299 B     build/static/css/main.c17080f1.css
# ...
  1. Install this library:
    $ npm install --save json-schema-deref-sync

    And import it anywhere:

    import deref from 'json-schema-deref-sync'; // in src/App.js
  2. Try to build:
$ npm run build

> my-app@0.1.0 build /Users/angelika/my-app
> react-scripts build

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

    ./node_modules/json-schema-deref-sync/lib/utils.js:70

Exactly the same thing happens in my company project that I set up without create-react-app. It uses uglifyjs-webpack-plugin which started to crash after I imported this library. The reason for the crash is that the let keyword is included in the webpack output file which I try to then minify.

ERROR in bundle.js from UglifyJs
Unexpected token: name (n) [bundle.js:1,607398]

In my node_modules, this is the directory tree for this project:

$ tree
.
├── ISSUE_TEMPLATE.md
├── LICENSE
├── LICENSE.txt
├── README.md`
├── dist
│   ├── index.js
│   ├── loaders
│   │   └── file.js
│   └── utils.js
├── lib
│   ├── index.js
│   ├── loaders
│   │   └── file.js
│   └── utils.js
├── node_modules
│   └── clone
│       ├── LICENSE
│       ├── README.md
│       ├── clone.iml
│       ├── clone.js
│       └── package.json
├── package.json
└── readme.hbs

I have noticed that dist includes the built library in ES5, but the main field in package.json points to lib/index.js instead of dist/index.js. I can get around this issue for myself by importing import deref from 'json-schema-deref-sync/dist';.

epicfaace commented 6 years ago

Same issue here.

epicfaace commented 6 years ago

Any updates on this?