Adding document field with keystone-next error: field doesn't define any adapters - keystonejs

When I use the field type document for one of my lists like so:
import { list } from '#keystone-next/keystone/schema';
import {
text,
timestamp,
select,
} from '#keystone-next/fields';
import { document } from '#keystone-next/fields-document';
export const Post = list({
fields: {
title: text(),
status: select({
options: [
{ label: 'Published', value: 'published' },
{ label: 'Draft', value: 'draft' },
],
ui: {
displayMode: 'segmented-control',
},
}),
content: document(),
publishDate: timestamp(),
},
});
However, the project fails to compile. Here's the error message:
Error: The type given for the 'Post.content' field doesn't define any adapters.
at /Users/johndoe/Projects/MyBlog/backend/node_modules/#keystonejs/keystone/lib/ListTypes/list.js:199:15
at Array.forEach (<anonymous>)
at List.initFields (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystonejs/keystone/lib/ListTypes/list.js:185:43)
at Keystone.createList (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystonejs/keystone/lib/Keystone/index.js:296:10)
at /Users/johndoe/Projects/MyBlog/backend/node_modules/#keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:663:16
at Array.forEach (<anonymous>)
at createKeystone (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:654:25)
at Object.createSystem (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:695:20)
at initKeystone (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystone-next/keystone/scripts/dist/keystone.cjs.dev.js:374:20)
at Server.<anonymous> (/Users/johndoe/Projects/MyBlog/backend/node_modules/#keystone-next/keystone/scripts/dist/keystone.cjs.dev.js:405:5)
at Object.onceWrapper (node:events:484:28)
at Server.emit (node:events:378:20)
at emitListeningNT (node:net:1344:10)
at processTicksAndRejections (node:internal/process/task_queues:80:21)
npm ERR! code 1
If I replace content: document() with content: text(), the project compiles successfully.
Here're are the relevant dependencies from package.json:
"#keystone-next/admin-ui": "^8.0.1",
"#keystone-next/auth": "^14.0.0",
"#keystone-next/cloudinary": "^2.0.9",
"#keystone-next/fields": "^4.1.1",
"#keystone-next/fields-document": "^5.0.0",
"#keystone-next/keystone": "^9.3.0",
"#keystone-next/types": "^12.0.0",
"#keystonejs/server-side-graphql-client": "^1.1.2",
"#types/nodemailer": "^6.4.0",
"dotenv": "^8.2.0",
"next": "^10.0.5",
"nodemailer": "^6.4.17",
"react": "^16.14.0",
"react-dom": "^16.14.0",

You may be using old version of react here, Keystone-next use react 17.02 currently. Try upgrade all dependencies, try yarn upgrade-interactive --latest to upgrade all your dependencies to latest.
Also. you have to provide some basic options to be able to use Document field properly, at least document({formatting: true}) config is desired otherwise it will be just text field with no formatting.
here is the example formatting without the need of relationship or other complex setup.
content: document({
formatting: true,
layouts: [
[1, 1],
[1, 1, 1],
[2, 1],
[1, 2],
[1, 2, 1],
],
links: true,
dividers: true,
}),
this will produce document field with following toolbar
for more complex example including working custom document field block see - https://github.com/keystonejs-contrib/keystonejs-document-demo

Related

Vue 2 - ESLint + Standard + Prettier

How do I create a Vue 2 project that uses ESLint + StandardJS + Prettier?
StandardJS's rules should naturally take precedence over Prettier's.
vue create only provides the following options:
ESLint + Standard
ESLint + Prettier
I tried 2 things:
I mixed the eslint configurations of both of the above options. It resulted in a dependency hell, and once that was solved it didn't really work as expected.
I added the prettier-standard package to my eslintrc.js, it didn't work as expected either. It's worth mentioning that prettier-standard works well when manually executing it from the command line.
I'm of course looking to set this up at the project config level and not at the IDE level.
Can you try this repo I've just created? Looks like it's working great from what I've tested.
https://github.com/kissu/so-eslint-standard-prettier-config
Notes
I created 2 projects and dumped the configuration of the standard one into the Prettier one, the changes can be seen in this commit
CLI's current version of #vue/eslint-config-standard is throwing an error (Environment key "es2021" is unknown) because it requires ESlint 7 to work, as shown in this changelog
bumping ESlint to the latest version 7.29.0, fixed the issue
to check your project's current version of ESlint, you can run npx eslint --version
of course, you need to have the ESlint extension enabled and Prettier one disabled (if using VScode), otherwise it may conflict
I've tried to remove #vue/prettier from
extends: ['plugin:vue/essential', 'eslint:recommended', '#vue/standard', '#vue/prettier']
and see if it's successfully removes any ; and it does!
The errors are indeed coming from ESlint (if we do remove #vue/prettier), and they're fixed by ESlint only upon save (after an ESlint server + VScode restart)!
Putting Prettier back works fine of course.
Luckly, I had a new PC, hence had the opportunity to try a whole fresh config with VScode.
I had to install ESlint only and have those settings into my settings.json
{
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.fixAll": true,
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
}
}
The formatting works perfectly and nothing more is required.
I have eslint 7.8.1 with Vue Prettier on and i don't have any problem, maybe the version of eslint that you have is not compatible with Prettier or maybe your eslint have some errors?
In each way i will put my eslint configuration and maybe it will help you!
module.exports = {
env: {
'browser': true,
'es6': true,
'node': true
},
parserOptions: {
'parser': 'babel-eslint'
},
extends: [
'#vue/standard',
'plugin:vue/recommended'
],
rules: {
"vue/html-indent": ["error", 4, {
"attribute": 1,
"closeBracket": 0,
"switchCase": 0,
"ignores": []
}],
"vue/max-attributes-per-line": [2, {
"singleline": 10,
"multiline": {
"max": 1,
"allowFirstLine": false
}
}],
'indent': ['error', 4],
'vue/component-name-in-template-casing': ['error', 'kebab-case'],
'vue/script-indent': [
'error',
4,
{ 'baseIndent': 1 }
],
'space-before-function-paren': ['error', 'never'],
'semi': [2, "never"],
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off'
},
overrides: [
{
'files': ['*.vue'],
'rules': {
'indent': 'off'
}
}
]
}
Also maybe you have forgot some of the devDependecies on package.json, those are mine
"eslint": "^7.8.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2"
Hope that those will help you !

Eslint no-extra-parens rule does not work

I have a vue project with an ESLint and prettier config like so:
"#typescript-eslint/eslint-plugin": "^4.26.1",
"#typescript-eslint/parser": "^4.26.1",
"#vue/eslint-config-prettier": "^6.0.0",
"#vue/eslint-config-typescript": "^7.0.0",
"eslint": "^7.28.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-vue": "^7.9.0",
"prettier": "^2.3.1",
All of the packages should be up to date.
I get this error in VSCode and in the console, which I would like to supress because I want to allow such parantheses for better reading:
As far as I can read, this is what the no-extra-parens rule is for, but I cannot get it to work.
The documentation (https://eslint.org/docs/rules/no-extra-parens) states that it has an object option with several adjustments to this rule. If I, for an example, try any of these options:
"no-extra-parens": "0",
or
"no-extra-parens" :{
"returnAssign": false,
"nestedBinaryExpressions": false,
"ignoreJSX": "none|all|multi-line|single-line",
"enforceForArrowConditionals": false,
"enforceForSequenceExpressions": false,
"enforceForNewInMemberExpressions": false,
"enforceForFunctionPrototypeMethods": false
},
... the error in VSCode dissapears, and everything seems to be working fine. But upon serve the console throws this error:
I´ve tried with
"no-extra-parens": 0,
as the console says, but then the rule is ignored and the first rule break error is shown.
I´ve tried to define the rule in alot of different ways with arrays and objects, setting it to "off", etc. But either the rule does not work in VSCode, or the console states that the rule definition is invalid.
This is my .eslintrc.js file:
module.exports = {
root: true,
env: {
node: true
},
extends: [
"plugin:vue/essential",
"eslint:recommended",
"#vue/typescript/recommended",
"#vue/prettier",
"#vue/prettier/#typescript-eslint"
],
parserOptions: {
ecmaVersion: 2020,
ecmaFeatures: {
"jsx": false
},
},
rules: {
"no-extra-parens": 0,
"no-console": ["warn", { allow: ["warn", "error"] }],
"no-debugger": "warn",
"curly": "error",
"quotes": [
"error",
"single"
],
"#typescript-eslint/ban-ts-comment": "off",
"#typescript-eslint/ban-ts-ignore": "off",
"#typescript-eslint/no-explicit-any": "off",
"#typescript-eslint/no-non-null-assertion": "off",
"#typescript-eslint/no-inferrable-types": "off",
"#typescript-eslint/no-use-before-define" : "off",
"#typescript-eslint/consistent-type-assertions" : "off",
"#typescript-eslint/no-empty-function": "warn",
"#typescript-eslint/interface-name-prefix": "off",
"#typescript-eslint/explicit-module-boundary-types": "off",
"#typescript-eslint/no-var-requires" : "off",
"#typescript-eslint/no-extra-parens": ["error"]
}
};
Any clue? 🤔
ESLint uses #typescript-eslint/no-extra-parens and doesn't need no-extra-parens, #typescript-eslint/* are supposed to aggregate * rules with same names, with the addition of features specific to TypeScript.
It's Prettier that affects this code, changing ESLint rules without disabling Prettier won't change the way it works.
The use of parentheses in this piece of code is redundant, as any as ... is a common construct in TypeScript and can be read and processed without parentheses:
const foo = bar as any as Foo;
Double as can be avoided in this case with:
const foo: Foo = bar as any;
Parentheses are necessary where type assertion is used as a part of an expression, in this case they will be kept by Prettier:
(bar as any as Foo).baz()
Prettier provides a consistent way to format the code with little configurability, this is its purpose, it shouldn't be expected to be fine-tuned for specific styles.
In case it's vital for the code to be formatted the way it is, and the setup uses Prettier through ESLint, it can be disabled where needed:
// eslint-disable-next-line prettier/prettier

Webpack source maps for some .vue (and .ts) files no longer contain original code (sourcesContent)

Edit [23-7-2019]
After further research, I found that not ALL .vue files have this problem. Some do still show the original source code.
It looks like one of the loaders that is used, might be the culprit for the problems (with "vue-loader" as my first 'target').
In files that DO show the source code, the relevant part of the source map file looks like this:
Whereas the same part of the source map in the files without the source code, looks like this:
So for some reason, the "harmony default export" of the vue-loader seems to be missing for the latter type of files.
Previous issue text
Since a few days, the source maps for my .vue files no longer contain the original code (sourcesContent).
A number of source map files are generated by Webpack, but none of them contain the actual code: only minified or otherwise 'compressed' versions of the code, which are not very usable. They look like this:
The Typescript (.ts) files in my project, look almost correct, but still contain some minor forms of modification, e.g.:
What I have tried:
- I have searched Stackoverflow, and found a number of similar questions (e.g. like WebPack sourcemaps confusing (duplicated files)) with possible fixes, but none of them fixed my problem;
- I have compared my latest (Webpack) changes with that of about a week (and 2 weeks) ago, when all was working okay. And I have compared it also to a very
similar project that still produces correct source maps, including
for .vue files.
- I have tried various settings for the "devtool" setting in the Webpack config, but nothing helped.
- I am not using Uglify (which is mentioned a lot when people have a problem with source maps), so that cannot be the problem;
- I have tried updating a number of build related packages, so that they are equal to those of the project which is still working correctly, but the problem remains.
- I checked different browsers, but the problem occurs both in Chrome and Firefox (and I checked that their source map settings are set to 'on', which they have to be as the other project is working with the same settings). I even tried IE11, but that didn't help either.
My starting scripts in package.json look like this:
"build-watch": "webpack -d --watch true --config webpack.dev.config.js",
"build-release": "webpack -p --config webpack.production.config.js",
"build-dev": "webpack -d --config webpack.dev.config.js",
The devDependencies look like this:
"devDependencies": {
"#babel/core": "^7.5.5",
"#babel/plugin-proposal-class-properties": "^7.5.5",
"#babel/plugin-proposal-object-rest-spread": "^7.5.5",
"#babel/preset-env": "^7.5.5",
"#babel/preset-typescript": "^7.3.3",
"#types/bootstrap": "^4.3.1",
"#types/jest": "^24.0.15",
"#types/jquery": "^3.3.30",
"#types/webpack": "^4.4.35",
"#vue/cli-plugin-e2e-cypress": "^3.9.0",
"#vue/cli-plugin-eslint": "^3.9.2",
"#vue/cli-plugin-typescript": "^3.9.0",
"#vue/cli-plugin-unit-jest": "^3.9.0",
"#vue/cli-service": "^3.9.3",
"#vue/eslint-config-standard": "^4.0.0",
"#vue/eslint-config-typescript": "^4.0.0",
"#vue/test-utils": "1.0.0-beta.29",
"assets-webpack-plugin": "^3.9.10",
"babel-loader": "^8.0.6",
"babel-preset-vue": "^2.0.2",
"cache-loader": "^4.1.0",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.1.0",
"cssnano": "^4.1.10",
"cypress": "^3.4.0",
"es6-promise": "^4.2.8",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.2.3",
"globule": "^1.2.1",
"mini-css-extract-plugin": "^0.7.0",
"node-sass": "^4.12.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"postcss-increase-specificity": "^0.6.0",
"postcss-loader": "^3.0.0",
"style-loader": "^0.23.1",
"ts-jest": "^24.0.2",
"ts-loader": "^6.0.4",
"typescript": "^3.5.3",
"url-loader": "^2.0.1",
"vue-loader": "^15.7.1",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.36.1",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.6" },
And the most relevant parts of my Webpack development config (excluding stuff like those related to webfonts) are these:
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const AssetsPlugin = require('assets-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const bundleOutputDir = './wwwroot/dist';
const NODE_PATH = path.join(__dirname, "node_modules");
const CACHE_PATH = path.join(NODE_PATH, '.cache/vue');
const VUE_VERSION = require('vue/package.json').version;
const VUE_LOADER_VERSION = require('vue-loader/package.json').version;
const bundleConfig = require('./bundles.config.js');
const buildId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
const config = {
entry: bundleConfig.entries,
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/'
},
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.css$/,
exclude: [
path.resolve(__dirname, "wwwroot", "Content"),
path.resolve(__dirname, "src", "common")
],
use: [
'vue-style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
},
{
test: /\.css$/,
include: [
path.resolve(__dirname, "wwwroot", "Content"),
path.resolve(__dirname, "src", "common")
],
use: [
'vue-style-loader',
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
cacheDirectory: CACHE_PATH,
cacheIdentifier: [
'development',
webpack.version,
VUE_VERSION,
VUE_LOADER_VERSION
].join('|')
}
},
{
test: /\.tsx$/,
loaders: 'babel-loader',
include: /src/
},
{
test: /\.ts$/,
loaders: 'ts-loader',
include: /src/,
options: {
appendTsSuffixTo: [
/\.vue$/
]
}
}, ...
]
},
devtool: "cheap-module-eval-source-map",
resolve: {
extensions: [
'.js',
'.vue',
'.tsx',
'.ts'
],
alias: {
'~#': path.resolve('src'),
'vue$': 'vue/dist/vue.esm.js',
'bootstrap-vue$': 'bootstrap-vue/dist/bootstrap-vue.esm.js'
}
},
plugins: [
new VueLoaderPlugin(),
new webpack.ProvidePlugin({
'Promise': 'es6-promise'
}),
new CleanWebpackPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new MiniCssExtractPlugin({ filename: "[name].css" }),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: false } }],
}
}),
new webpack.WatchIgnorePlugin([
/\.d\.ts$/
]),
new AssetsPlugin({
filename: 'webpack.assets.json',
path: bundleOutputDir,
prettyPrint: true,
metadata: { buildId: buildId }
})
],
stats: {
modules: false,
entrypoints: false,
children: false
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all"
}
}
}
} };
I have totally run out of clues, so if anyone can give some, that would be great!
In the end, it turned out to be a source maps caching issue...! Which seems like a "duh!" solution to the problem, but it is not, really.
Because, it turns out that Chrome is very persistent with the caching of the source maps (at least, so it seems to me).
Whenever I start debugging, I use the Debug option of Visual Studio 2019. Which will then launch a new Chrome instance to do the debugging/testing in. I always assumed that this was done, to make sure you were using a 'fresh' version of the browser (e.g. with an empty cache, and the like). It turns out that this does not apply to the source maps of this browser instance...!
I found out that caching was the problem, because I had a window open in my 'regular' Chrome, which was also set to the local development environment. And I decided to see how the source maps where shown there, more to sort of amuse myself and less because I thought that would lead to anything. And in that browser, the correct source maps were & are shown.
So I went back to my (still open) development instance of Chrome. And in that, I already had disabled the cache in the devtools, both in the settings, and via the checkbox on the network tab. But still the source maps remained cached. So I emptied the browser cache via the regular settings of Chrome. But still the source maps remained cached. I changed the settings in Visual Studio to open an incognito version of Chrome for debugging. And even now, I still see the incorrect/old source maps there (while they show up just fine in the regular browser instance)...
Very weird all of this, but at least I can now start working/debugging again!

Vue-CLI with 4 space identation

I am totally new to Vue.
I want to use the CLI and I want to have 4 space indentation (with typescript and vuex). But after 24 hours of struggling I am no closer to getting anything working. If it is impossible let me know too.
I thought that tslint was the way to go, but could not find a solution. So I tried eslint and added this to package.json
"devDependencies": {
"#vue/cli-plugin-eslint": "^3.0.4",
"#vue/cli-plugin-pwa": "^3.0.4",
"#vue/cli-plugin-typescript": "^3.0.4",
"#vue/cli-service": "^3.0.4",
"#vue/eslint-config-prettier": "^3.0.4",
"#vue/eslint-config-typescript": "^3.0.4",
"eslint": "^5.6.1",
"eslint-plugin-vue": "^5.0.0-beta.3", // <------------------
"typescript": "^3.0.0",
"vue-template-compiler": "^2.5.17"
}
Then is eslintrc I have
module.exports = {
root: true,
env: {
node: true
},
extends: ["plugin:vue/essential", "#vue/prettier", "#vue/typescript"],
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
"vue/script-indent": ["error", 4, { baseIndent: 1 }],
indent: ["error", 4]
},
parserOptions: {
parser: "typescript-eslint-parser"
}
};
then when I run
$ npx eslint --fix *.js
=============
WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.
You may find that it works just fine, or you may not.
SUPPORTED TYPESCRIPT VERSIONS: ~3.0.1
YOUR TYPESCRIPT VERSION: 3.1.1
Please only submit bug reports when using the officially supported version.
=============
/Users/x/code/sync/vue/restos2/postcss.config.js
2:1 error Expected indentation of 4 spaces but found 2 indent
3:1 error Expected indentation of 8 spaces but found 4 indent
4:1 error Expected indentation of 4 spaces but found 2 indent
✖ 3 problems (3 errors, 0 warnings)
3 errors and 0 warnings potentially fixable with the `--fix` option.
but the problem is that no files ever get changed.
As described in the tslint doc, the indent rule doesnt fix wrong amount of indentation characters, it only fixes the character type, this means that it can convert tabs to spaces and vice versa, but it doesnt fix 4 spaces to 2 spaces
NOTE: auto-fixing will only convert invalid indent whitespace to the desired type, it will not fix invalid whitespace sizes.
https://palantir.github.io/tslint/rules/indent/
So yeah, you'd have to go with eslint. I dont see you full eslintrc file, but I think that the main problem may be this line: indent: ["error", 4]. Try removing that.
This eslint config is working for me:
{
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"#vue/typescript"
],
"rules": {
"vue/script-indent": ["error",2,{"baseIndent": 1}]
},
"parserOptions": {
"parser": "typescript-eslint-parser"
}
}
And run with npm run lint

Grunt build failing - ParseError: 'import' and 'export' may appear only with 'sourceType: module'

I have gone through many posts on github and stackoverflow. I have the following dev dependencies in my package.json for the es6 to es5 transpilation.
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^6.0.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^15.0.0",
"grunt-browserify": "^5.2.0",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0"
I have setup a grunt task to compile my es6 file to es5 using babelify as transformer and browserify.
browserify: {
dist: {
src: [‘src/component/myes6.js’],
dest: ‘dist/src/component/myes5.js’,
options: {
transform: [
['babelify', {presets: [["es2015", { loose: true, modules: false }]]}]
],
browserifyOptions: {
debug: true
}
}
}
}
My es6 js file is importing a node module which is es6 js file and exported as function. I tried to follow many suggestion from various forums and looked through the babel/babelify/grunt-browserify documentation but could not land on a concrete conclusion.
Earlier I thought, it could be versions issue but I am now using all babel 6 version and latest browserify/grunt-browserify etc. But still, I am seeing the following error:
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Any help or pointers will be appreciated.
I've solved it installing esmify plugin npm install babel-plugin-esmify browser-resolve --save-dev.
browserify: {
dist: {
src: ['src/component/myes6.js'],
dest: 'dist/src/component/myes5.js',
options: {
plugin: [
[require('esmify')]
],
transform: [
['babelify', {
presets: [["es2015", { loose: true, modules: false }]]
}
]
}
}
},
I haven't tried running it, but the square brackets around your browserify dist/src shouldn't be there. Try running this file without them.