npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dataroadinc/rdf-loader

v0.0.9

Published

A webpack loader for importing RDF files directly as JavaScript modules

Readme

@dataroadinc/rdf-loader

npm version npm downloads License Node.js TypeScript CI Release

A webpack loader for importing RDF (Resource Description Framework) files directly as JavaScript modules in Next.js and other webpack-based applications.

Features

Note: This loader is designed for webpack and has experimental support for Turbopack. The loader supports both CommonJS and ES module environments, making it compatible with various build configurations. For production use, we recommend using webpack instead of Turbopack.

Installation

npm install --save-dev @dataroadinc/rdf-loader
# or
yarn add --dev @dataroadinc/rdf-loader
# or
pnpm add -D @dataroadinc/rdf-loader

Usage

1. Configure Webpack

Add the loader to your webpack configuration:

// webpack.config.js or next.config.mjs
module.exports = {
  module: {
    rules: [
      {
        test: /\.(ttl|nt|nq|rdf|jsonld|trig)$/,
        use: ["@dataroadinc/rdf-loader"],
      },
    ],
  },
}

Or with options:

// webpack.config.js or next.config.mjs
module.exports = {
  module: {
    rules: [
      {
        test: /\.(ttl|nt|nq|rdf|jsonld|trig)$/,
        use: [
          {
            loader: "@dataroadinc/rdf-loader",
            options: {
              failOnError: false,
              verbose: true,
            },
          },
        ],
      },
    ],
  },
}

1.1. Turbopack Support (Experimental)

For Next.js applications using Turbopack, you can configure the loader in your next.config.js:

// next.config.js
module.exports = {
  experimental: {
    turbo: {
      rules: {
        "*.ttl": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
        "*.nt": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
        "*.nq": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
        "*.rdf": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
        "*.jsonld": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
        "*.trig": {
          loaders: ["@dataroadinc/rdf-loader"],
          as: "*.js",
          options: { verbose: true, failOnError: false },
        },
      },
    },
  },
}

Note: Turbopack support is experimental and may not work in all scenarios. The loader has been tested with Turbopack configuration but runtime behavior may vary.

2. TypeScript Configuration

Add type declarations to your global.d.ts or similar:

declare module "*.ttl" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

declare module "*.nt" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

declare module "*.nq" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

declare module "*.rdf" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

declare module "*.jsonld" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

declare module "*.trig" {
  import { DataFactory, Quad } from "@rdfjs/types"
  export default function (factory: DataFactory): Quad[]
}

3. Import RDF Files

import rdfFactory from "rdf-ext"
import storyQuadsFunction from "./story.ttl"

// Load the RDF data
const quads = storyQuadsFunction({ factory: rdfFactory })
const dataset = rdfFactory.dataset(quads)

// Now you can work with the RDF dataset
for (const quad of dataset) {
  console.log(
    `${quad.subject.value} ${quad.predicate.value} ${quad.object.value}`
  )
}

4. Loader Options

The loader supports the following options:

  • failOnError (boolean, default: false): Whether to fail the build on parsing errors
  • verbose (boolean, default: false): Whether to log detailed information about processing
  • format (string): Override the detected format based on file extension

5. Troubleshooting

Issue: "Module not found: Package path . is not exported"

Solution: Use the loader with the full path in webpack configuration:

const path = require("path")

module.exports = {
  webpack: config => {
    config.module.rules.push({
      test: /\.(ttl|nt|nq|rdf|jsonld|trig)$/,
      use: [
        path.resolve(
          __dirname,
          "node_modules/@dataroadinc/rdf-loader/dist/index.js"
        ),
      ],
    })
    return config
  },
}

Issue: TypeScript errors with RDF imports

Solution: Ensure you have the type declarations in your global.d.ts file and that @rdfjs/types is installed as a dependency.

Dependencies

This package depends on:

  • @rdfjs/formats-common: For parsing various RDF formats
  • @rdfjs/serializer-rdfjs: For serializing RDF to JavaScript
  • string-to-stream: For converting string content to streams

Example RDF File

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/> .

ex:Person
  a rdfs:Class ;
  rdfs:label "Person" ;
  rdfs:comment "A human being" .

License

MIT

Testing

This package includes comprehensive tests for:

  • Unit Tests: Core loader functionality with various RDF formats
  • Webpack Integration Tests: Configuration validation for webpack-based projects
  • Turbopack Integration Tests: Configuration validation for Turbopack-based projects
  • External File Tests: Support for RDF files outside the src directory

Run tests with:

pnpm test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.