#Build fails when importing package, works on dev.

1 messages · Page 1 of 1 (latest)

untold sable
#

I'm using the ics-to-json package. This imports / works fine on dev, but fails on an npm run build:

---
import EventCard from "../components/EventCard/EventCard.astro";
import Layout from "../layouts/Layout.astro";
import icsToJson from "ics-to-json";

// Get ICS text however you like, example below
// Make sure you have the right CORS settings if needed
const convert = async (fileLocation: string): Promise<MusicEvent[]> => {
  const icsRes = await fetch(fileLocation);
  const icsData = await icsRes.text();
  // Convert
  const data = icsToJson(icsData);
  return data;
};

const allEvents = await convert("public/calendar/music-calendar.ics");
const events = allEvents.filter((musicEvent) => musicEvent.summary);

interface MusicEvent {
  summary: string;
  description: string;
  startDate: string;
  endDate: string;
}
---

<Layout>
  <div class="bg-gray-50">
    <div
      class="mx-auto max-w-7xl py-16 px-4 sm:py-24 sm:px-6 lg:flex lg:justify-between lg:px-8"
    >
      <div class="w-full space-y-16">
        <div class="max-w-xl">
          <h2
            class="text-4xl font-bold tracking-tight text-black sm:text-5xl lg:text-6xl"
          >
            Event Schedule
          </h2>
          <p class="mt-5 text-xl text-black">
            Join us for live music performances by local artists, featuring a
            mix of traditional Hawaiian and contemporary tunes. Enjoy great
            food, drinks, and entertainment. We can't wait to see you at our
            next live music event! Aloha!
          </p>
        </div>

        <div class="event-block space-y-8">
          {
            events.map((event) => (
              <EventCard artist={event.summary} startDate={event.startDate} />
            ))
          }
        </div>
      </div>
    </div>
  </div>
</Layout>

The package is correctly included in my package.json as a dependency. Here's the error I get:

 error   icsToJson is not a function
  File:
    /Users/personalmac/projects/beastside-kitchen/node_modules/astro/dist/runtime/server/render/page.js:66:30
  Code:
      65 |   }
    > 66 |   const factoryReturnValue = await componentFactory(result, props, children);
         |                              ^
      67 |   if (isAstroComponent(factoryReturnValue)) {
      68 |     let iterable = renderAstroComponent(factoryReturnValue);
      69 |     let init = result.response;
tribal perch
#

did you install the typescript typings?

#

it could be the docs are wrong

#

the typings would tell you

untold sable
untold sable
#

I imagine that has to do with it then. How can I just tell TypeScript "Hey man, this old ass package doesn't have types. Don't worry about it."?

tribal perch
#

sounds like its an actual problem not the typings then, I looked at the source and there really is a default export that you're importing so

untold sable
#

Do I have to make my own typings?

#

Sry, I'm new to TS

tribal perch
#

you could but its not going to solve this

untold sable
#

Got it got it

tribal perch
#

not sure why dev is different here

untold sable
#

Hmmmm

tribal perch
#

you did npm i right

untold sable
#

Let me hard delete package-lock.json and try again

#

justtttttt in case

tribal perch
#

delete node modules too

untold sable
#

kk

#

Doing npm cache clean –-force for good measure

#

I did accidentally install it as a dev dependency earlier, so that might've got stuck somehow

#

Nothing. 😦

#

Going to quit my job and become a plumber, I'm stumped

tribal perch
#

any npm warnings?

#

worst case you could "vendor" it

#

eg copy paste their entire src from github into a dir called vendors

untold sable
#

same one

#

Full build log:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/Users/personalmac/.nvm/versions/node/v14.17.0/bin/node',
1 verbose cli   '/Users/personalmac/.nvm/versions/node/v14.17.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle @example/[email protected]~prebuild: @example/[email protected]
6 info lifecycle @example/[email protected]~build: @example/[email protected]
7 verbose lifecycle @example/[email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle @example/[email protected]~build: PATH: /Users/personalmac/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/personalmac/projects/beastside-kitchen/node_modules/.bin:/usr/local/opt/mysql-client/bin:/usr/local/opt/mysql-client/bin:/Users/personalmac/.nvm/versions/node/v14.17.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/mysql-client/bin:/Users/personalmac/.nvm/versions/node/v14.17.0/bin:/Users/newing/bin:/usr/local/mysql/bin:/Users/newing/bin:/usr/local/mysql/bin
9 verbose lifecycle @example/[email protected]~build: CWD: /Users/personalmac/projects/beastside-kitchen
10 silly lifecycle @example/[email protected]~build: Args: [ '-c', 'astro build' ]
11 silly lifecycle @example/[email protected]~build: Returned: code: 1  signal: null
12 info lifecycle @example/[email protected]~build: Failed to exec build script
13 verbose stack Error: @example/[email protected] build: `astro build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/personalmac/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:376:20)
13 verbose stack     at ChildProcess.<anonymous> (/Users/personalmac/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:376:20)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid @example/[email protected]
15 verbose cwd /Users/personalmac/projects/beastside-kitchen
16 verbose Darwin 21.6.0
17 verbose argv "/Users/personalmac/.nvm/versions/node/v14.17.0/bin/node" "/Users/personalmac/.nvm/versions/node/v14.17.0/bin/npm" "run" "build"
18 verbose node v14.17.0
19 verbose npm  v6.14.13
20 error code ELIFECYCLE
21 error errno 1
22 error @example/[email protected] build: `astro build`
22 error Exit status 1
23 error Failed at the @example/[email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
#

OMG I THINK I KNOW WHAT IT IS

tribal perch
#

?

untold sable
#

node version

#

I changed it for work

#

I use 14 for work, I use 18 for my client work

#

it's totally possible that has something to do with it

#

yay, new error

#

It doesn't like my public path

#

Let me type out some more info

#
 error   Failed to parse URL from public/calendar/music-calendar.ics
  File:
    /Users/personalmac/projects/beastside-kitchen/node_modules/astro/dist/runtime/server/render/page.js:89:30
  Code:
    88 |   }
    > 89 |   const factoryReturnValue = await componentFactory(result, props, children);
         |                              ^
      90 |   const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue);
      91 |   if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) {
      92 |     await bufferHeadContent(result);
  Stacktrace:
TypeError: Failed to parse URL from public/calendar/music-calendar.ics

Shouldn't public/... be sufficient in Astro?

#

Nvm, I'm getting a fetch failed now

untold sable