Skip to content
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 use aldeed:schema-index, getting error "index" is not a supported property #41

Open
nicu-chiciuc opened this issue Nov 9, 2018 · 7 comments

Comments

@nicu-chiciuc
Copy link

I'm having this issue with aldeed:schema-index although I think the same issue would apply also to other meteor packages. Basically what this package does is add several options to SimpleSchema.

SimpleSchema.extendOptions([
  'index', // one of Number, String, Boolean
  'unique', // Boolean
  'sparse', // Boolean
]);

The problem is that I'm getting the following error:

Error: Invalid definition for username field: "index" is not a supported property

I've tried to use your example of React by adding simple-schema and I'm getting the exact same error.
It seems like the meteor package is not executed or is using a different version of SimpleSchema.

Or maybe I missed something in how to actually use this package since I don't have much experience in meteor.

@ardatan
Copy link
Owner

ardatan commented Nov 9, 2018

Does this work well without webpack?

@nicu-chiciuc
Copy link
Author

Yes, I think it might have something to do with the fact that simpl-schema is installed using npm and the aldeed:schema-index is installed using atmosphere and it basically extends the package from npm.

schema-index common.js

// collection2 checks to make sure that simpl-schema package is added
import SimpleSchema from 'simpl-schema';
import Collection2 from 'meteor/aldeed:collection2';

// Extend the schema options allowed by SimpleSchema
SimpleSchema.extendOptions([
  'index', // one of Number, String, Boolean
  'unique', // Boolean
  'sparse', // Boolean
]);

Collection2.on('schema.attached', (collection, ss) => {
  // Define validation error messages
  if (ss.version >= 2 && ss.messageBox && typeof ss.messageBox.messages === 'function') {
    ss.messageBox.messages({
      en: {
        notUnique: '{{label}} must be unique',
      },
    });
  }
});

I'll probably have to figure out how the code in meteor-webpack manages stuff like this, but maybe you'd have some tips.

@pmogollons
Copy link

I just had this issue too. It might be possible that schema-index loads first and the simpl-schema gets loaded and reconfigured somehow and that removes the extended options.

Im going to try to add package functionality in app code and check if that works.

@nicu-chiciuc where you able to find a solution?

@pmogollons
Copy link

I was able to workaround the schema-index issue by not importing the schemas in the client code.

@nicu-chiciuc
Copy link
Author

@pmogollons We left the idea of switching to meteor-webpack for awhile since it wasn't crucial at the moment, but I'll definitely try your solution when I'll get around to it.

@ardatan
Copy link
Owner

ardatan commented Dec 7, 2018

Can you share your webpack configuration?

@pmogollons
Copy link

Unfortunately I was not able to make the project work correctly app compiles without issues but get an error on browser console. I think the problem is related to issue #40

Here goes my webpack config.

const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const meteorExternals = require('webpack-meteor-externals');
// const SentryWebpackPlugin = require('@sentry/webpack-plugin');


const clientConfig = {
  entry: './imports/startup/client/index.js',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          ...JSON.parse(fs.readFileSync(path.resolve(__dirname, './.babelrc')))
        }
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.less$/,
        use: ['style-loader', 'less-loader']
      },
      {
        test: /\.json($|\?)/,
        use: 'json-loader'
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './client/main.html'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],
  resolve: {
    extensions: ['*', '.js', '.jsx']
  },
  externals: [
    meteorExternals()
  ],
  devServer: {
    hot: true
  }
};


const serverConfig = {
  entry: [
    './imports/startup/server/index.js'
  ],
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          ...JSON.parse(fs.readFileSync(path.resolve(__dirname, './.babelrc')))
        }
      }
    ]
  },
  target: 'node',
  // devServer: {
  //   hot: true
  // },
  externals: [
    meteorExternals(),
    nodeExternals()
  ]
};

module.exports = [clientConfig, serverConfig];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants