Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netlify adapter fails if route name that ends in ".js" #6490

Closed
adamjkb opened this issue Aug 31, 2022 · 0 comments · Fixed by #6492
Closed

Netlify adapter fails if route name that ends in ".js" #6490

adamjkb opened this issue Aug 31, 2022 · 0 comments · Fixed by #6492

Comments

@adamjkb
Copy link
Contributor

adamjkb commented Aug 31, 2022

Describe the bug

Netlify adapter fails on the following line if route name end with .js extension (i.e. /config.js):

glob('**/*.js', { cwd: '.netlify/server' }).forEach((file) => {
	const filepath = `.netlify/server/${file}`;
	const input = readFileSync(filepath, 'utf8'); // <-------
	const output = esbuild.transformSync(input, { format: 'cjs', target: 'node12' }).code;
	writeFileSync(filepath, output);
});

https://github.com/sveltejs/kit/blob/master/packages/adapter-netlify/index.js#L168

Fails because it's trying to read a directory as a file.

Reproduction

https://github.com/adamjkb/kit-netlify-adapter-read-error
/config.js/+server.js

netlify build log

Logs

10:07:58 PM: Build ready to start
10:08:00 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
10:08:00 PM: build-image tag: v4.10.1
10:08:00 PM: buildbot version: 67e75f1ba713a8213d4b5a8ccf9708af751e2390
10:08:00 PM: Fetching cached dependencies
10:08:00 PM: Failed to fetch cache, continuing with build
10:08:00 PM: Starting to prepare the repo for build
10:08:00 PM: No cached dependencies found. Cloning fresh repo
10:08:00 PM: git clone https://github.com/adamjkb/kit-netlify-adapter-read-error
10:08:01 PM: Preparing Git Reference refs/heads/main
10:08:01 PM: Parsing package.json dependencies
10:08:02 PM: Starting build script
10:08:02 PM: Installing dependencies
10:08:02 PM: Python version set to 2.7
10:08:02 PM: Downloading and installing node v16.17.0...
10:08:02 PM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz...
10:08:03 PM: Computing checksum with sha256sum
10:08:03 PM: Checksums matched!
10:08:06 PM: Now using node v16.17.0 (npm v8.15.0)
10:08:06 PM: Started restoring cached build plugins
10:08:06 PM: Finished restoring cached build plugins
10:08:06 PM: Attempting ruby version 2.7.2, read from environment
10:08:06 PM: Using ruby version 2.7.2
10:08:07 PM: Using PHP version 8.0
10:08:07 PM: No npm workspaces detected
10:08:07 PM: Started restoring cached node modules
10:08:07 PM: Finished restoring cached node modules
10:08:07 PM: Installing NPM modules using NPM version 8.15.0
10:08:07 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:08:07 PM: npm WARN config location in the cache, and they are managed by
10:08:07 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:08:08 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:08:08 PM: npm WARN config location in the cache, and they are managed by
10:08:08 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:08:08 PM: npm WARN ERESOLVE overriding peer dependency
10:08:08 PM: npm WARN While resolving: @sveltejs/vite-plugin-svelte@1.0.3
10:08:08 PM: npm WARN Found: vite@3.1.0-beta.1
10:08:08 PM: npm WARN node_modules/vite
10:08:08 PM: npm WARN   dev vite@"^3.1.0-beta.1" from the root project
10:08:08 PM: npm WARN   1 more (@sveltejs/kit)
10:08:08 PM: npm WARN
10:08:08 PM: npm WARN Could not resolve dependency:
10:08:08 PM: npm WARN peer vite@"^3.0.0" from @sveltejs/vite-plugin-svelte@1.0.3
10:08:08 PM: npm WARN node_modules/@sveltejs/vite-plugin-svelte
10:08:08 PM: npm WARN   @sveltejs/vite-plugin-svelte@"^1.0.3" from @sveltejs/kit@1.0.0-next.459
10:08:08 PM: npm WARN   node_modules/@sveltejs/kit
10:08:08 PM: npm WARN
10:08:08 PM: npm WARN Conflicting peer dependency: vite@3.0.9
10:08:08 PM: npm WARN node_modules/vite
10:08:08 PM: npm WARN   peer vite@"^3.0.0" from @sveltejs/vite-plugin-svelte@1.0.3
10:08:08 PM: npm WARN   node_modules/@sveltejs/vite-plugin-svelte
10:08:08 PM: npm WARN     @sveltejs/vite-plugin-svelte@"^1.0.3" from @sveltejs/kit@1.0.0-next.459
10:08:08 PM: npm WARN     node_modules/@sveltejs/kit
10:08:09 PM: added 124 packages, and audited 125 packages in 2s
10:08:09 PM: 12 packages are looking for funding
10:08:09 PM:   run `npm fund` for details
10:08:09 PM: found 0 vulnerabilities
10:08:09 PM: NPM modules installed
10:08:10 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:08:10 PM: npm WARN config location in the cache, and they are managed by
10:08:10 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:08:10 PM: Started restoring cached go cache
10:08:10 PM: Finished restoring cached go cache
10:08:10 PM: Installing Go version 1.17 (requested 1.17)
10:08:14 PM: unset GOOS;
10:08:14 PM: unset GOARCH;
10:08:14 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
10:08:14 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
10:08:14 PM: go version >&2;
10:08:14 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
10:08:14 PM: go version go1.17 linux/amd64
10:08:14 PM: Installing missing commands
10:08:14 PM: Verify run directory
10:08:15 PM: ​
10:08:15 PM: ────────────────────────────────────────────────────────────────
10:08:15 PM:   Netlify Build                                                 
10:08:15 PM: ────────────────────────────────────────────────────────────────
10:08:15 PM: ​
10:08:15 PM: ❯ Version
10:08:15 PM:   @netlify/build 27.16.1
10:08:15 PM: ​
10:08:15 PM: ❯ Flags
10:08:15 PM:   baseRelDir: true
10:08:15 PM:   buildId: 630fcdae7d3cae365356dabf
10:08:15 PM:   deployId: 630fcdae7d3cae365356dac1
10:08:15 PM: ​
10:08:15 PM: ❯ Current directory
10:08:15 PM:   /opt/build/repo
10:08:15 PM: ​
10:08:15 PM: ❯ Config file
10:08:15 PM:   No config file was defined: using default values.
10:08:15 PM: ​
10:08:15 PM: ❯ Context
10:08:15 PM:   production
10:08:15 PM: ​
10:08:15 PM: ────────────────────────────────────────────────────────────────
10:08:15 PM:   1. Build command from Netlify app                             
10:08:15 PM: ────────────────────────────────────────────────────────────────
10:08:15 PM: ​
10:08:15 PM: $ npm run build
10:08:15 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:08:15 PM: npm WARN config location in the cache, and they are managed by
10:08:15 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:08:15 PM: > kit-netlify-adapter-read-error@0.0.1 build
10:08:15 PM: > vite build
10:08:16 PM: vite v3.1.0-beta.1 building for production...
10:08:16 PM: transforming...
10:08:16 PM: ✓ 31 modules transformed.
10:08:16 PM: rendering chunks...
10:08:16 PM: vite v3.1.0-beta.1 building SSR bundle for production...
10:08:16 PM: transforming...
10:08:16 PM: ✓ 43 modules transformed.
10:08:16 PM: Generated an empty chunk: "hooks"
10:08:16 PM: rendering chunks...
10:08:16 PM: .svelte-kit/output/server/vite-manifest.json                       1.27 KiB
10:08:16 PM: .svelte-kit/output/server/index.js                                 63.56 KiB
10:08:16 PM: .svelte-kit/output/server/entries/endpoints/config.js/_server.js   0.17 KiB
10:08:16 PM: .svelte-kit/output/server/entries/fallbacks/layout.svelte.js       0.23 KiB
10:08:16 PM: .svelte-kit/output/server/entries/fallbacks/error.svelte.js        1.50 KiB
10:08:16 PM: .svelte-kit/output/server/entries/pages/_page.svelte.js            0.23 KiB
10:08:16 PM: .svelte-kit/output/server/chunks/index.js                          3.10 KiB
10:08:16 PM: .svelte-kit/output/server/chunks/hooks.js                          0.00 KiB
10:08:17 PM: Run npm run preview to preview your production build locally.
10:08:17 PM: .svelte-kit/output/client/vite-manifest.json                                         2.33 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/components/layout.svelte-54ce02e1.js        0.53 KiB / gzip: 0.35 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/components/error.svelte-1ad7a6bb.js         2.07 KiB / gzip: 0.95 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/components/pages/_page.svelte-4064e16b.js   0.44 KiB / gzip: 0.30 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/chunks/singletons-16fed83b.js               1.81 KiB / gzip: 0.97 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/chunks/0-e33b1d15.js                        0.12 KiB / gzip: 0.11 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/chunks/1-0dc74399.js                        0.15 KiB / gzip: 0.13 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/start-3abb3d04.js                           21.20 KiB / gzip: 8.43 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/chunks/index-2b05990c.js                    6.62 KiB / gzip: 2.70 KiB
10:08:17 PM: .svelte-kit/output/client/_app/immutable/chunks/2-ee4f66e3.js                        0.12 KiB / gzip: 0.12 KiB
10:08:17 PM: 
10:08:17 PM: > Using @sveltejs/adapter-netlify
10:08:17 PM:   No netlify.toml found. Using default publish directory. Consult https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration for more details 
10:08:17 PM: error during build:
10:08:17 PM: Error: EISDIR: illegal operation on a directory, read
10:08:17 PM:     at Object.readSync (node:fs:742:3)
10:08:17 PM:     at tryReadSync (node:fs:442:20)
10:08:17 PM:     at readFileSync (node:fs:488:19)
10:08:17 PM:     at file:///opt/build/repo/node_modules/@sveltejs/adapter-netlify/index.js:168:18
10:08:17 PM:     at Array.forEach (<anonymous>)
10:08:17 PM:     at generate_lambda_functions (file:///opt/build/repo/node_modules/@sveltejs/adapter-netlify/index.js:166:47)
10:08:17 PM:     at Object.adapt (file:///opt/build/repo/node_modules/@sveltejs/adapter-netlify/index.js:80:11)
10:08:17 PM:     at adapt (file:///opt/build/repo/node_modules/@sveltejs/adapter-auto/index.js:20:22)
10:08:18 PM: Creating deploy upload records
10:08:17 PM:     at adapt (file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:8)
10:08:17 PM:     at Object.handler (file:///opt/build/repo/node_modules/@sveltejs/kit/src/exports/vite/index.js:485:12)
10:08:17 PM: ​
10:08:17 PM: ────────────────────────────────────────────────────────────────
10:08:18 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
10:08:17 PM:   "build.command" failed                                        
10:08:17 PM: ────────────────────────────────────────────────────────────────
10:08:17 PM: ​
10:08:17 PM:   Error message
10:08:17 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
10:08:17 PM: ​
10:08:17 PM:   Error location
10:08:17 PM:   In Build command from Netlify app:
10:08:17 PM:   npm run build
10:08:17 PM: ​
10:08:17 PM:   Resolved config
10:08:17 PM:   build:
10:08:17 PM:     command: npm run build
10:08:17 PM:     commandOrigin: ui
10:08:17 PM:     publish: /opt/build/repo/build
10:08:17 PM:     publishOrigin: ui
10:08:17 PM: Caching artifacts
10:08:17 PM: Started saving node modules
10:08:17 PM: Finished saving node modules
10:08:17 PM: Started saving build plugins
10:08:17 PM: Finished saving build plugins
10:08:17 PM: Started saving pip cache
10:08:17 PM: Finished saving pip cache
10:08:17 PM: Started saving emacs cask dependencies
10:08:17 PM: Finished saving emacs cask dependencies
10:08:17 PM: Started saving maven dependencies
10:08:17 PM: Finished saving maven dependencies
10:08:17 PM: Started saving boot dependencies
10:08:17 PM: Finished saving boot dependencies
10:08:17 PM: Started saving rust rustup cache
10:08:17 PM: Finished saving rust rustup cache
10:08:17 PM: Started saving go dependencies
10:08:17 PM: Finished saving go dependencies
10:08:18 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:08:18 PM: Failing build: Failed to build site
10:08:18 PM: Finished processing build request in 18.220923219s

System Info

N/A (Deployment env only)

Severity

serious, but I can work around it

Additional Information

No response

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

Successfully merging a pull request may close this issue.

1 participant