【发布时间】:2020-02-21 13:25:00
【问题描述】:
导出我的 nextjs 应用时出现以下错误:
SyntaxError: Unexpected token {
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
这是我的next.config.js:
import {getBlogPosts} from "./src/api";
import {mapPosts} from "./src/mappers/BlogMapper";
module.exports = {
async exportPathMap() {
const response = await getBlogPosts();
const posts = mapPosts(response);
const pages = posts.reduce(
(pages, post) =>
Object.assign({}, pages, {
[`/blog/${post.uid}`]: {page: '/blog/[uid]'},
}),
{}
);
// combine the map of post pages with the home
return Object.assign({}, pages, {
'/': {page: '/'},
})
},
};
src/api 文件:
import Prismic from "prismic-javascript";
import {Client} from "./prismic-configuration";
export const getBlogPosts = (req) => {
return Client(req).query(
Prismic.Predicates.at("document.type", "post"),
{orderings: "[my.post.date desc]"}
);
};
export const getBlogPost = (req, uid) => {
return Client(req).getByUID("post", uid, null);
};
我在文档中发现了这个问题,但我不确定由谁来解决它:
避免使用目标中不可用的新 JavaScript 功能 Node.js 版本。 next.config.js 不会被 Webpack、Babel 解析 或 TypeScript。
【问题讨论】:
标签: javascript webpack next.js