vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.95k stars 239 forks source link

Using local version of the package #511

Closed vfonic closed 5 years ago

vfonic commented 5 years ago

I'm having quite some issues with using the package, both outside of meteor and using local version.

Basically, the package has quite some requirements/assumptions about which packages I'm using in my codebase.

This is the only package that requires me to modify my webpack configuration (to add @babel/plugin-proposal-class-properties and @babel/plugin-transform-flow-strip-types).

I'm also getting warnings about not having some meteor packages, including check method/package. This broke my CI build and I also had to modify the CI configuration to pass the build by not marking warnings are build breaks. I'd say that this is not optimal solution. :)

I tried to use the package from the local path, but so far I haven't had any luck.

This is the error I'm getting:

.../JavaScript/uniforms/packages/uniforms/src/ValidatedForm.js
Module not found: Can't resolve '@babel/runtime/helpers/assertThisInitialized' in '.../JavaScript/uniforms/packages/uniforms/src'

These are the dependencies in my package.json:

```js "dependencies": { "@babel/core": "^7.1.2", "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/plugin-transform-classes": "^7.2.2", "@babel/plugin-transform-flow-strip-types": "^7.2.3", "@babel/plugin-transform-runtime": "^7.1.0", "@babel/preset-env": "^7.0.0", "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.3.1", "@svgr/webpack": "2.4.1", "@types/react": "^16.4.14", "autoprefixer": "^9.1.1", "axios": "^0.18.0", "babel-core": "7.0.0-bridge.0", "babel-eslint": "9.0.0", "babel-jest": "23.6.0", "babel-loader": "8.0.4", "babel-plugin-inline-react-svg": "^1.0.0", "babel-plugin-named-asset-import": "^0.2.2", "babel-preset-react-app": "^5.0.3", "bfj": "6.1.1", "case-sensitive-paths-webpack-plugin": "2.1.2", "chalk": "2.4.1", "classnames": "^2.2.6", "cross-env": "^5.1.3", "css-loader": "1.0.0", "dayjs": "^1.7.7", "dotenv": "6.0.0", "dotenv-expand": "4.2.0", "emotion": "^9.2.12", "eslint": "5.6.0", "eslint-config-prettier": "^3.1.0", "eslint-config-react-app": "^3.0.3", "eslint-loader": "2.1.1", "eslint-plugin-flowtype": "2.50.1", "eslint-plugin-import": "2.14.0", "eslint-plugin-jsx-a11y": "6.1.1", "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-react": "7.11.1", "file-loader": "2.0.0", "fs-extra": "7.0.0", "fuzzy": "^0.1.3", "html-webpack-plugin": "4.0.0-alpha.2", "identity-obj-proxy": "3.0.0", "invariant": "^2.2.4", "jest": "23.6.0", "jest-pnp-resolver": "1.0.1", "jest-resolve": "23.6.0", "lodash": "^4.17.11", "mini-css-extract-plugin": "0.4.3", "optimize-css-assets-webpack-plugin": "5.0.1", "pluralize": "^7.0.0", "pnp-webpack-plugin": "1.1.0", "polished": "^2.2.0", "postcss-flexbugs-fixes": "4.1.0", "postcss-loader": "3.0.0", "postcss-preset-env": "6.0.6", "postcss-safe-parser": "4.0.1", "prettier": "^1.14.3", "prettier-eslint-cli": "^4.7.1", "prop-types": "^15.6.2", "query-string": "^6.2.0", "raw-loader": "^0.5.1", "react": "^16.7.0-alpha.2", "react-app-polyfill": "^0.1.3", "react-autocomplete": "^1.8.1", "react-dev-utils": "^6.0.4", "react-dom": "^16.7.0-alpha.2", "react-emotion": "^9.2.12", "react-router-dom": "^4.3.1", "react-toastify": "^4.4.3", "resolve": "1.8.1", "sass-loader": "7.1.0", "semantic-ui-react": "^0.82.2", "simpl-schema": "^1.5.3", "style-loader": "0.23.0", "terser-webpack-plugin": "1.1.0", "uniforms": "file:../../uniforms/packages/uniforms/src", "url-loader": "1.1.1", "webpack": "4.19.1", "webpack-dev-server": "3.1.9", "webpack-manifest-plugin": "2.0.4", "workbox-webpack-plugin": "3.6.2" } } ```

Any suggestions of what I'm missing?

I believe documentation could mention more how to use this package locally and maybe try to detach meteor dependencies completely? (I did check the demo, but I still don't know what I'm missing that's breaking the build)

Thanks!

radekmie commented 5 years ago

Hi @vfonic. Using uniforms in a non-Meteor project is working out of the box if you use the correct version of the code. We do ship both transpiled (/) and original (/src) sources.

Meteor dependencies are required in a try {...} catch (...) {...} block and indirect (const r = require; r(...)), so it's just working. Eventually, you'll see a warning about it. And yes, it'll be decoupled in the next major version (it'll be a breaking change). If you really want to silence them, simply map them to something else (e.g. with module resolver).

As I've also worked in such a configuration, I'd rather recommend you to put custom uniforms directly into your project code and treat them like normal components.

I won't be able to debug your project, but I can assure you, that the demo project is working.

vfonic commented 5 years ago

Indeed, the demo project works. :)

I just wanted to point out that I haven't seen as a common pattern an npm package to require me to add babel plugins so that I can use it.

As I've also worked in such a configuration, I'd rather recommend you to put custom uniforms directly into your project code and treat them like normal components.

That's a good idea! I'll do that.

And yes, it'll be decoupled in the next major version.

Thanks!

radekmie commented 5 years ago

As there's no more discussion here, I'm closing.