Skip to content

Commit 9b3f7e3

Browse files
author
Fabian Schultz
committed
Add warning for relative paths in source-filesystem.
1 parent 9afeebd commit 9b3f7e3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/gatsby-source-filesystem/src/gatsby-node.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const chokidar = require(`chokidar`)
22
const fs = require(`fs`)
3+
const path = require(`path`)
34
const { Machine } = require(`xstate`)
45

56
const { createFileNode } = require(`./create-file-node`)
@@ -86,6 +87,19 @@ See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
8687
`)
8788
}
8889

90+
// Validate that the path is absolute.
91+
// Absolute paths are required to resolve images correctly.
92+
if (!path.isAbsolute(pluginOptions.path)) {
93+
reporter.warn(`The path passed to gatsby-source-filesystem is relative:
94+
95+
${pluginOptions.path}
96+
97+
It is recommended to use an absolute path.
98+
99+
See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
100+
`)
101+
}
102+
89103
const fsMachine = createFSMachine()
90104
let currentState = fsMachine.initialState
91105
let fileNodeQueue = new Map()

0 commit comments

Comments
 (0)