Property 'setPreviewData' does not exist on type 'NowResponse' #13593
Answered
by
timneutkens
Vadorequest
asked this question in
Help
-
Bug reportDescribe the bugUsing
To Reproduceimport { NowRequest, NowResponse } from '@now/node';
import { createLogger } from '@unly/utils-simple-logger';
import Sentry, { configureReq } from '../../utils/monitoring/sentry';
const fileLabel = 'api/preview';
const logger = createLogger({
label: fileLabel,
});
export const error = async (req: NowRequest, res: NowResponse): Promise<void> => {
try {
configureReq(req);
if (process.env.APP_STAGE !== 'production') {
res.setPreviewData({}); // ERROR HERE
console.log('Preview mode enabled'); // eslint-disable-line no-console
res.writeHead(307, { Location: '/' });
res.end();
} else {
res.end('');
console.error('Preview mode is not allowed in production'); // eslint-disable-line no-console
}
} catch (e) {
logger.error(e.message);
Sentry.withScope((scope): void => {
scope.setTag('fileLabel', fileLabel);
Sentry.captureException(e);
});
res.json({
error: true,
message: process.env.APP_STAGE === 'production' ? undefined : e.message,
});
}
};
export default error; Expected behaviorIt should work (type should exist). System information
|
Beta Was this translation helpful? Give feedback.
Answered by
timneutkens
May 30, 2020
Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
timneutkens
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setPreviewData
can only be used in Next.js API routes (pages/api/*
) not inside of Vercel API routes as this is a Next.js feature / integrated into Next.js. Potentially you're incorrectly typing your Next.js API route, itNextApiRequest
andNextApiRequest
from'next'
: