我寫有反應,節點的應用程序,但我的本地主機未運行,而我有這樣的錯誤:無法讀取的不確定(節點JS)屬性「路徑」
UNHANDLED REJECTION TypeError: Cannot read property 'path' of undefined
所有NPM-模塊安裝,但這個錯誤不允許啓動我的項目。這是我第一次嘗試用節點編寫代碼,所以也許答案就近了。 下面我的node.js:
const _ = require("lodash")
const Promise = require("bluebird")
const path = require("path")
const select = require(`unist-util-select`)
const fs = require(`fs-extra`)
exports.createPages = ({ graphql, boundActionCreators }) => {
const { upsertPage } = boundActionCreators
return new Promise((resolve, reject) => {
const pages = []
const blogPost = path.resolve("./src/templates/blog-post.js")
resolve(
graphql(
`
{
allMarkdownRemark(limit: 1000) {
edges {
node {
fields {
slug
}
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
// Create blog posts pages.
_.each(result.data.allMarkdownRemark.edges, edge => {
upsertPage({
path: edge.node.fields.slug, // required
component: blogPost,
context: {
slug: edge.node.fields.slug,
},
})
})
})
)
})
}
// Add custom slug for blog posts to both File and MarkdownRemark nodes.
exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => {
const { addFieldToNode } = boundActionCreators
if (node.internal.type === `File`) {
const parsedFilePath = path.parse(node.relativePath)
const slug = `/${parsedFilePath.dir}/`
addFieldToNode({ node, fieldName: `slug`, fieldValue: slug })
} else if (node.internal.type === `MarkdownRemark`) {
const fileNode = getNode(node.parent)
addFieldToNode({
node,
fieldName: `slug`,
fieldValue: fileNode.fields.slug,
})
}
}
你能告訴我哪一行發生錯誤嗎? –
它並不是完全顯示行數,但它顯示了這一點: D:\ IT \ Valeria \ Work \ Project \ client-only-paths \ node_modules \ bluebird \ js \ release \ async.js:61 'fn = function(){throw arg; };' –