I'm creating a blog using Next.js + MDX-Bundler and trying to use remark-disable-tokenizers to disable "indented codeblock". But i'm not able to make it work. I found a reference here which says that we can use remark-disable-tokenizers for this purpose.
Here is my xdmoptions for reference:
import disableTokens from 'remark-disable-tokenizers';
xdmOptions(options) {
options.rehypePlugins = [
...(options.rehypePlugins ?? []),
rehypeSlug,
rehypeCodeTitles,
rehypePrism,
[disableTokens,
{
block: [
['indentedCode', 'indented code is not supported by MDX-Bundler']
]
}],
[
rehypeAutolinkHeadings,
{...}
]
];
return options;
},
Related
I've started to develop a multi-language web application with Next JS and Lingui.js
Lingui.js is using babel so I had to install it aswell.
I've followed this tutorial https://blog.logrocket.com/complete-guide-internationalization-nextjs/
After facing some issues i've also followed the official documentation of Lingui.js https://lingui.js.org/tutorials/setup-react.html
I faced a lot of issues with babel and typescript.
But now I struggle with following error, which I could not find any help with:
wait - compiling / (client and server)...
error - ./node_modules/resolve-from/index.js:3:0
Module not found: Can't resolve 'module'
Import trace for requested module:
./node_modules/import-fresh/index.js
./node_modules/cosmiconfig/dist/loaders.js
./node_modules/cosmiconfig/dist/index.js
./node_modules/babel-plugin-macros/dist/index.js
./node_modules/#lingui/macro/index.js
./src/pages/index.tsx
https://nextjs.org/docs/messages/module-not-found
false
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
at Home (webpack-internal:///./src/pages/index.tsx:36:51)
at I18nProvider (C:\Project\app\node_modules\#lingui\react\cjs\react.development.js:46:19)
at MyApp (webpack-internal:///./src/pages/_app.tsx:48:24)
at StyleRegistry (C:\Project\app\node_modules\styled-jsx\dist\index\index.js:671:34)
at AppContainer (C:\Project\app\node_modules\next\dist\server\render.js:394:29)
at AppContainerWithIsomorphicFiberStructure (C:\Project\app\node_modules\next\dist\server\render.js:424:57)
at div
at Body (C:\Project\app\node_modules\next\dist\server\render.js:701:21)
error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in,
or you might have mixed up default and named imports.
here is my babel.config.js
module.exports = {
presets: [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-typescript"
],
plugins: [
["#babel/plugin-transform-runtime",
{
"regenerator": true
}
],
[
"#babel/plugin-transform-react-jsx",
{
"runtime": "automatic"
}
],
[
'#babel/plugin-transform-runtime',
{
absoluteRuntime: false,
corejs: false,
helpers: true,
regenerator: true,
version: '7.0.0-beta.0',
},
'react-native-reanimated/plugin',
],
]
}
and my webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader']
}
]
}
};
The part with React.jsx: type is invalid is because of getStaticProps in index.tsx.
So this might be an separate issue
Have you already tried the solution mentioned here ?
webpack.config.js
node: {
module: "empty",
}
I ended up deleting everything I had from Babel and lingui and copied all imports from another project which was running.
Cannot name the difference between them, but it worked afterwards.
I created a cloud function project with firebase a few months ago, and used linting.
I recently created a new cloud function project with linting, and now the linter is complaining about random rules I never set. I don't remember it enforcing nearly the amount of style rules a few months ago.
Things like:
This line has a length of 95. Maximum allowed is 80
Missing JSDoc comment
Missing Trailing comma
expected indentation of 2 spaces but found 4
Strings must use singlequote
It's also not letting me use async/await.
I found out I can individually set these rules in my .eslintrc.js file, but that's annoying and I don't want to do that. By default, why aren't these rules disabled? I just want basic rules that make sure my code won't fail when run, not random style preferences like single/double quotes and max line length.
Is there any way to use just basic linting functionality with firebase functions?
I ran into the same issue as you. The new, more strict linting rules seem to come from the fact that Firebase functions use the "google" eslint base configuration plugin by default now. Read more about configuring ESLint plugins in the docs. My older Firebase functions were using tslint without issue.
Here's what my .eslintrc.js file looked like while I was getting style errors from eslint:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'google',
],
parser: '#typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['#typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
I deleted 'google' from the extends property, which seemed to resolve almost all of the style linting issues.
Now it looks like this:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
parser: '#typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['#typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
You can get rid of the google extends value but I would suggest keeping it and just turning off the rules that bother you the most, which for me is indentation and max length (of lines):
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
"quotes": ["error", "double"],
"indent": ["off"],
"max-len": ["off"],
},
};
For anyone who is confused by this, there is a lint config file in the Cloud Functions folder that you can edit. As of this answer, that file is named .eslintrc.js.
I'm working on a React Native application with AppSync, and following is my schema to the problem:
type JoineeDeletedConnection {
items: [Joinee]
nextToken: String
}
type Mutation {
deleteJoinee(ids: [ID!]): [Joinee]
}
In 'request mapping template' to resolver to deleteJoinee, I have following (following the tutorial from https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html):
#set($ids = [])
#foreach($id in ${ctx.args.ids})
#set($map = {})
$util.qr($map.put("id", $util.dynamodb.toString($id)))
$util.qr($ids.add($map))
#end
{
"version" : "2018-05-29",
"operation" : "BatchDeleteItem",
"tables" : {
"JoineesTable": $util.toJson($ids)
}
}
..and in 'response mapping template' to the resolver,
$util.toJson($ctx.result.data.JoineesTable)
The problem is, when I ran the query, I got empty result and nothing deleted to database as well:
// calling the query
mutation DeleteJoinee {
deleteJoinee(ids: ["xxxx", "xxxx"])
{
id
}
}
// returns
{
"data": {
"deleteJoinee": [
null
]
}
}
I finally able to solve this puzzle, thanks to the answer mentioned here to point me to some direction.
Although, I noticed that JoineesTable does have trusted entity/role to the IAM 'Roles' section, yet it wasn't working for some reason. Looking into this more, I noticed that the existing policy had following actions as default:
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem"
]
Once I added following two more actions to the list, things have started working:
"dynamodb:BatchWriteItem",
"dynamodb:BatchGetItem"
Thanks to #Vasileios Lekakis and #Ionut Trestian on this appSync quest )
We need to send certificates list to another application using REST API. So Object response contains
[
{
"id":1,
"orderId":123,
"certificateStatus":true,
"certificateNo":"xyz123abc",
"customer":{
"id":36,
"email":"abc#cc.com",
"firstName":"abc",
"lastName":"dfg",
"user":{
"id":23,
"username":"abc#cc.com",
"enabled":true,
"kycStatus":false
},
"_links":{
"self":{
"href":"\/app_dev.php\/api\/v1\/customers\/36"
}
}
},
"orderItem":{
"id":60,
"quantity":2,
"unitPrice":177581,
"total":355162,
"units":[
{
"id":1711,
"adjustments":[
],
"adjustmentsTotal":0
},
{
"id":1712,
"adjustments":[
],
"adjustmentsTotal":0
}
],
"unitsTotal":355162,
"adjustments":[
],
"adjustmentsTotal":0,
"variant":{
"id":334,
"code":"pool-gold-1oz",
"optionValues":[
],
"position":0,
"translations":{
"en_US":{
"locale":"en_US",
"id":334
}
},
"version":2,
"tracked":false,
"channelPricings":{
"UK_WEB":{
"channelCode":"UK_WEB",
"price":177582
},
"US_WEB":{
"channelCode":"US_WEB",
"price":177581
}
},
"_links":{
"self":{
"href":"\/app_dev.php\/api\/v1\/products\/pool-gold-1oz\/variants\/pool-gold-1oz"
}
}
},
"_links":{
"order":{
"href":"\/app_dev.php\/api\/v1\/orders\/29"
},
"product":{
"href":"\/app_dev.php\/api\/v1\/products\/pool-gold-1oz"
},
"variant":{
"href":"\/app_dev.php\/api\/v1\/products\/pool-gold-1oz\/variants\/pool-gold-1oz"
}
}
}
}
]
I want JSON response something like below sample response
- which need extra custom fields
- status code and message
- extra fields
- remove unwanted fields
{
"code":"custom_code_xxx",
"message":"Successful",
"data":[
{
"custom_extra_fields1":"asd",
"custom_extra_fields2":"xyz",
"id":1,
"orderId":123,
"certificateStatus":true,
"certificateNo":"xyz123abc",
"customer":{
"id":36,
"email":"abc#xyz.com",
"firstName":"abc",
"lastName":"dfg",
"user":{
"id":23,
"username":"abc#xyz.com",
"enabled":true,
"kycStatus":false
}
},
"orderItem":{
"id":60,
"quantity":2,
"unitPrice":177581,
"total":355162,
"unitsTotal":355162
}
}
]
}
Any best practice we can use to simplify JSON response ? or we need to construct an array in the required format
When you use something like e.g. JMS Serializer Bundle you can use
Virtual Properties for additional custom fields.
And Groups and/or Exclusion Policies to get rid of unwanted fields.
When using the Symfony Serializer you have at least the option of Groups to exclude some fields.
To add additional fields I'd either use simply an additional Getter in your Entity (no clean approach but helps) or work with custom normalizers and/or encoders.
Stefun,
You should create a new data transfer object containing the properties that you want as response. Then return that object as a json.
You then create an assembler class that builds your DTO based on the original object.
I'm trying to find if there's a nice way using SelectTokens and JsonPath to find all controls with type="check" and no "options". So an example JSON could be:
Value = #"{
""subsections"": [
{
""name"": ""Subsection Name"",
""caption"": ""Subsection Caption""
},
],
""controls"": [
{ ""type"" : ""check"",
""name"" : ""Checkbox2"",
""caption"" : ""Checkbox Caption 2"",
""options"" : [
{ ""caption"" : ""Yes"" },
{ ""caption"" : ""No"" }
]
},
{ ""type"" : ""check"",
""name"" : ""Checkbox2"",
""caption"" : ""Checkbox Caption 2"",
}
]
}"
I'm trying things like: $..controls[?(#.type=='check' && !(#.options))] but I can't see any option to test for a not exists.
The only option that I can think of is getting all check types and then using Linq to filter those without options. Just wondering if there is a way to do it solely through JsonPath?
Kind regards
Sidharth