Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

template.html unable to be found if --cwd and --src are the same #1069

Closed
noahlh opened this issue Jan 24, 2020 · 1 comment · Fixed by #1070
Closed

template.html unable to be found if --cwd and --src are the same #1069

noahlh opened this issue Jan 24, 2020 · 1 comment · Fixed by #1070

Comments

@noahlh
Copy link
Contributor

noahlh commented Jan 24, 2020

Note: I'm reporting this bug for the record, but have a simple solution which I'll submit as a PR shortly.

Describe the bug
If sapper's current working directory and the src directory are the same, src_dir in manifest-server.mjs will be blank (and template.html will be unable to be found or served)

Logs

(ERROR) Error: ENOENT: no such file or directory, open '/template.html'
(ERROR)     at Object.openSync (fs.js:440:3)
(ERROR)     at Object.readFileSync (fs.js:342:35)
(ERROR)     at read_template (webpack:///./node_modules/@sapper/server.mjs?:2497:41)
(ERROR)     at template (webpack:///./node_modules/@sapper/server.mjs?:2158:11)
(ERROR)     at handle_page (webpack:///./node_modules/@sapper/server.mjs?:2460:17)
(ERROR)     at processTicksAndRejections (internal/process/task_queues.js:93:5) {
(ERROR)   errno: -2,
(ERROR)   syscall: 'open',
(ERROR)   code: 'ENOENT',
(ERROR)   path: '/template.html'

To Reproduce
Setup a custom sapper installation where the src files live in the root instead of src/ or some other custom subdirectory.

Expected behavior
With the proper arguments (--src, etc.), the system should function as normal.

Severity
This is a minor issue and will likely not come into play for most standard sapper installations, but in rare cases where the directory structure is more rigid, this can be a problem!

Additional context / investigation
The issue is based in src/core/create_app.ts:182-183

const build_dir = posixify(path.relative(cwd, dest));
const src_dir = posixify(path.relative(cwd, src));

If cwd & dest or cwd & src are the path.relative will return a blank string. From the docs:

The path.relative() method returns the relative path from from to to based on the current working directory. If from and to each resolve to the same path (after calling path.resolve() on each), a zero-length string is returned.

In this case, however, a zero-length string produces undesired behavior (a dead location).

The solution is to wrap each call in path.normalize(), which instead of a zero-length string will produce "." as the result, pointing to the current directory (as it should).

@Conduitry
Copy link
Member

Fixed in 0.27.14.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants