SvelteKit site builds locally, fails with Netlify, rollup import issue

Site: iil.is / iil-is.netlify.app

In one of my pages I am importing a BibTeX / .bib file which starts with @inproceedings{...:

import pubs from '../publications.bib?raw'

I am using Vite’s ?raw modifier as described here: Features | Vite

This builds fine locally but Netlify fails saying it can’t parse the file:

[rollup-plugin-dynamic-import-variables] Unexpected character '@' (2:0)

Why is Netlify behaving differently here? What can I do to get around this error?

Full Deploy log:

4:11:56 PM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/jack-lydfu-a/builds
4:12:15 PM: Build ready to start
4:12:17 PM: build-image version: 081db65c3e4ce8423fedb40e7689a87de6f84667
4:12:17 PM: build-image tag: v4.3.1
4:12:17 PM: buildbot version: 97a6b2cacb208d0706f4c310f966af375d45e5e6
4:12:17 PM: Fetching cached dependencies
4:12:17 PM: Starting to download cache of 123.5MB
4:12:18 PM: Finished downloading cache in 990.574574ms
4:12:18 PM: Starting to extract cache
4:12:22 PM: Finished extracting cache in 4.258175837s
4:12:22 PM: Finished fetching cache in 5.300344046s
4:12:22 PM: Starting to prepare the repo for build
4:12:23 PM: Preparing Git Reference refs/heads/master
4:12:24 PM: Parsing package.json dependencies
4:12:24 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus 'build/' in the Netlify UI
4:12:24 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'functions' versus 'functions/' in the Netlify UI
4:12:25 PM: Starting build script
4:12:25 PM: Installing dependencies
4:12:25 PM: Python version set to 2.7
4:12:25 PM: Started restoring cached node version
4:12:28 PM: Finished restoring cached node version
4:12:28 PM: Attempting node version '14' from .nvmrc
4:12:29 PM: v14.17.6 is already installed.
4:12:29 PM: Now using node v14.17.6 (npm v6.14.15)
4:12:29 PM: Started restoring cached build plugins
4:12:29 PM: Finished restoring cached build plugins
4:12:29 PM: Attempting ruby version 2.7.2, read from environment
4:12:31 PM: Using ruby version 2.7.2
4:12:31 PM: Using PHP version 8.0
4:12:31 PM: Started restoring cached node modules
4:12:31 PM: Finished restoring cached node modules
4:12:32 PM: Installing NPM modules using NPM version 6.14.15
4:12:37 PM: npm WARN hagura-svelte@0.0.1 No repository field.
4:12:37 PM: npm WARN hagura-svelte@0.0.1 No license field.
4:12:37 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
4:12:37 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
4:12:37 PM: added 3 packages from 3 contributors, updated 3 packages and audited 266 packages in 4.446s
4:12:37 PM: 46 packages are looking for funding
4:12:37 PM:   run `npm fund` for details
4:12:37 PM: found 0 vulnerabilities
4:12:37 PM: NPM modules installed
4:12:37 PM: Started restoring cached go cache
4:12:37 PM: Finished restoring cached go cache
4:12:38 PM: go version go1.16.5 linux/amd64
4:12:38 PM: go version go1.16.5 linux/amd64
4:12:38 PM: Installing missing commands
4:12:38 PM: Verify run directory
4:12:39 PM: ​
4:12:39 PM: ────────────────────────────────────────────────────────────────
4:12:39 PM:   Netlify Build                                                 
4:12:39 PM: ────────────────────────────────────────────────────────────────
4:12:39 PM: ​
4:12:39 PM: ❯ Version
4:12:39 PM:   @netlify/build 18.12.0
4:12:39 PM: ​
4:12:39 PM: ❯ Flags
4:12:39 PM:   baseRelDir: true
4:12:39 PM:   buildId: 614b55cc3f79a60007d324ee
4:12:39 PM:   deployId: 614b55cc3f79a60007d324f0
4:12:39 PM: ​
4:12:39 PM: ❯ Current directory
4:12:39 PM:   /opt/build/repo
4:12:39 PM: ​
4:12:39 PM: ❯ Config file
4:12:39 PM:   /opt/build/repo/netlify.toml
4:12:39 PM: ​
4:12:39 PM: ❯ Context
4:12:39 PM:   production
4:12:39 PM: ​
4:12:39 PM: ────────────────────────────────────────────────────────────────
4:12:39 PM:   1. build.command from netlify.toml                            
4:12:39 PM: ────────────────────────────────────────────────────────────────
4:12:39 PM: ​
4:12:39 PM: $ npm run build
4:12:40 PM: > hagura-svelte@0.0.1 build /opt/build/repo
4:12:40 PM: > svelte-kit build
4:12:40 PM: vite v2.5.10 building for production...
4:12:41 PM: transforming...
4:12:52 PM: ✓ 84 modules transformed.
4:12:53 PM: rendering chunks...
4:12:58 PM: .svelte-kit/output/client/_app/manifest.json                                 8.47 KiB
4:12:58 PM: .svelte-kit/output/client/_app/error.svelte-e5fe83ab.js                      1.55 KiB / brotli: 0.64 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/index.md-56082df3.js                    4.26 KiB / brotli: 1.56 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/__layout.svelte-b27253a8.js             8.27 KiB / brotli: 2.41 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/research/index.svelte-368b4b62.js       3.68 KiB / brotli: 1.45 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/collaborate.md-21d0eb84.js              4.87 KiB / brotli: 1.56 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/research/halldorophone.md-7cc533e0.js   1.84 KiB / brotli: 0.74 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/publications/index.md-c83de459.js       12.22 KiB / brotli: 4.00 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/research/secondproject.md-2a62931b.js   1.12 KiB / brotli: 0.56 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/research/firstproject.md-d1195383.js    1.10 KiB / brotli: 0.57 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/openlab/2.md-88e000ee.js                1.15 KiB / brotli: 0.60 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/openlab/1.md-236e2bec.js                1.15 KiB / brotli: 0.60 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/openlab/3.md-bea5913d.js                1.15 KiB / brotli: 0.60 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/openlab/4.md-cdeb6ca5.js                1.15 KiB / brotli: 0.60 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/openlab/index.svelte-1fb7f428.js        5.04 KiB / brotli: 1.75 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/blog/secondpost.md-5a687938.js          5.37 KiB / brotli: 1.38 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/blog/index.svelte-b89fe3dc.js           2.99 KiB / brotli: 1.27 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/about.md-3fcd26a1.js                    6.62 KiB / brotli: 1.87 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/news/index.svelte-ed371bf1.js           3.58 KiB / brotli: 1.42 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/blog/third-post.svx-da54fe16.js         5.36 KiB / brotli: 1.39 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/news/seconditem.md-a47e02d9.js          0.51 KiB / brotli: 0.28 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/news/firstitem.md-03cc6c9a.js           0.48 KiB / brotli: 0.28 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/news/thirditem.md-423759ea.js           0.53 KiB / brotli: 0.28 KiB
4:12:58 PM: .svelte-kit/output/client/_app/chunks/store-a44d1c42.js                      0.16 KiB / brotli: 0.13 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/blog/firstpost.md-150d4746.js           6.48 KiB / brotli: 1.82 KiB
4:12:58 PM: .svelte-kit/output/client/_app/start-b6b5b088.js                             23.25 KiB / brotli: 6.30 KiB
4:12:58 PM: .svelte-kit/output/client/_app/chunks/ResearchProject-7f48ab44.js            1.49 KiB / brotli: 0.74 KiB
4:12:58 PM: .svelte-kit/output/client/_app/assets/start-464e9d0a.css                     0.19 KiB / brotli: 0.12 KiB
4:12:58 PM: .svelte-kit/output/client/_app/chunks/OpenLabEvent-107116aa.js               1.72 KiB / brotli: 0.82 KiB
4:12:58 PM: .svelte-kit/output/client/_app/assets/pages/index.md-8a123744.css            0.04 KiB / brotli: 0.04 KiB
4:12:58 PM: .svelte-kit/output/client/_app/pages/team/index.md-b3837ada.js               10.38 KiB / brotli: 3.17 KiB
4:12:58 PM: .svelte-kit/output/client/_app/assets/vendor-8daff541.css                    1.53 KiB / brotli: 0.32 KiB
4:12:58 PM: .svelte-kit/output/client/_app/assets/pages/__layout.svelte-f476f4f2.css     6.77 KiB / brotli: 1.89 KiB
4:12:58 PM: .svelte-kit/output/client/_app/chunks/vendor-d8ca3ed4.js                     58.23 KiB / brotli: 13.18 KiB
4:12:58 PM: vite v2.5.10 building SSR bundle for production...
4:12:58 PM: transforming...
4:12:58 PM: ✓ 4 modules transformed.
4:12:58 PM: [rollup-plugin-dynamic-import-variables] Unexpected character '@' (2:0)
4:12:58 PM: file: /opt/build/repo/src/routes/publications/publications.bib:2:0
4:12:58 PM: > Unexpected character '@' (2:0)
4:12:58 PM: SyntaxError: Unexpected character '@' (2:0)
4:12:58 PM:     at Parser.pp$5.raise (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:19495:13)
4:12:58 PM:     at Parser.pp$9.getTokenFromCode (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:21160:8)
4:12:58 PM:     at Parser.pp$9.readToken (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:20844:15)
4:12:58 PM:     at Parser.pp$9.nextToken (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:20835:15)
4:12:58 PM:     at Parser.parse (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:16657:8)
4:12:58 PM:     at Function.parse (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:16700:35)
4:12:58 PM:     at Graph.contextParse (/opt/build/repo/node_modules/rollup/dist/shared/rollup.js:22746:38)
4:12:58 PM:     at Object.transform (/opt/build/repo/node_modules/vite/dist/node/chunks/dep-36bf480c.js:43090:27)
4:12:58 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/vite/dist/node/chunks/dep-36bf480c.js:51272:33)
4:12:58 PM:     at /opt/build/repo/node_modules/rollup/dist/shared/rollup.js:22620:25
4:12:58 PM: npm ERR! code ELIFECYCLE
4:12:58 PM: npm ERR! errno 1
4:12:58 PM: npm ERR! hagura-svelte@0.0.1 build: `svelte-kit build`
4:12:58 PM: npm ERR! Exit status 1
4:12:58 PM: npm ERR!
4:12:58 PM: npm ERR! Failed at the hagura-svelte@0.0.1 build script.
4:12:58 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
4:12:58 PM: npm ERR! A complete log of this run can be found in:
4:12:58 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-09-22T16_12_58_654Z-debug.log
4:12:58 PM: ​
4:12:58 PM: ────────────────────────────────────────────────────────────────
4:12:58 PM:   "build.command" failed                                        
4:12:58 PM: ────────────────────────────────────────────────────────────────
4:12:58 PM: ​
4:12:58 PM:   Error message
4:12:58 PM:   Command failed with exit code 1: npm run build
4:12:58 PM: ​
4:12:58 PM:   Error location
4:12:58 PM:   In build.command from netlify.toml:
4:12:58 PM:   npm run build
4:12:58 PM: ​
4:12:58 PM:   Resolved config
4:12:58 PM:   build:
4:12:58 PM:     command: npm run build
4:12:58 PM:     commandOrigin: config
4:12:58 PM:     publish: /opt/build/repo/build
4:12:58 PM:     publishOrigin: config
4:12:58 PM:   functionsDirectory: /opt/build/repo/functions
4:12:59 PM: Caching artifacts
4:12:59 PM: Started saving node modules
4:12:59 PM: Finished saving node modules
4:12:59 PM: Started saving build plugins
4:12:59 PM: Finished saving build plugins
4:12:59 PM: Started saving pip cache
4:12:59 PM: Finished saving pip cache
4:12:59 PM: Started saving emacs cask dependencies
4:12:59 PM: Finished saving emacs cask dependencies
4:12:59 PM: Started saving maven dependencies
4:12:59 PM: Finished saving maven dependencies
4:12:59 PM: Started saving boot dependencies
4:12:59 PM: Finished saving boot dependencies
4:12:59 PM: Started saving rust rustup cache
4:12:59 PM: Finished saving rust rustup cache
4:12:59 PM: Started saving go dependencies
4:12:59 PM: Creating deploy upload records
4:12:59 PM: Finished saving go dependencies
4:12:59 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:12:59 PM: Failing build: Failed to build site
4:12:59 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
4:12:59 PM: Finished processing build request in 42.296357257s

I noticed that the package/repo Netlify is referring to:

Has actually been migrated elsewhere:

Does this imply Netlify is using an out of date package?

Hi @jarm,

Are you trying npm run build locally? Based on this issue:

The error doesn’t appear in dev but appears when you build for production.

Thanks!

I couldn’t find a workaround for this issue, so I moved the .bib to the static folder and I load it using fetch instead of import.