Open nicu-chiciuc opened 5 years ago
Does this work well without webpack?
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.
// 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.
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?
I was able to workaround the schema-index issue by not importing the schemas in the client code.
@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.
Can you share your webpack configuration?
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];
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.The problem is that I'm getting the following error:
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.