Skip to content

Suggestion: Improve Alcaeus Web DX by documenting eliminating/reducing Node.js dependencies? #288

@lambdakris

Description

@lambdakris

While trying to use Alcaeus with Angular (which uses webpack for tooling under the hood) following the Alcaeus getting started instructions, I ran into a couple of issues when trying to run the application through the webpack based tooling.

Repro steps

Here is what I tried:

  1. Download, unzip, and open our example Angular App: alcaeus-app.zip (based on the default Angular CLI template)

  2. Install Alcaeus

npm install --save alcaeus
  1. Import and use Alcaeus from inside a component
import { Component, OnInit } from '@angular/core';
import { Hydra } from 'alcaeus/web';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
  async ngOnInit(): Promise<void> {
    var hydraRsrc = await Hydra.loadResource('https://sources.wikibus.org/');
    var root = hydraRsrc.representation!.root!;
    console.log(root.toJSON());
  }
}
  1. Try to run the application
npm start
  1. Notice and troubleshoot problems (see below)

Problems found

Problem 1 - resolving 'stream'

  • Problem
./node_modules/jsonld-streaming-parser/lib/JsonLdParser.js:14:17-34 - Error: Module not found: Error: Can't resolve 'stream' in 'C:\Users\Kris.garcia\code\open\sema\alcaeus-examples\getting-started-example\node_modules\jsonld-streaming-parser\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }
  • Solution

* Same solution as Problem 2 & 3

  1. Install the node-polyfill-webpack-plugin package
npm install --save-dev node-polyfill-webpack-plugin
  1. Configure the node-polyfill-webpack-plugin in the custom-webpack.config.ts file
import { Configuration } from 'webpack';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';

export default {
  plugins: [
    new NodePolyfillPlugin()
   ]
} as Configuration;

Problem 2 - resolving 'url'

  • Problem
./node_modules/parse-link-header/index.js:4:10-24 - Error: Module not found: Error: Can't resolve 'url' in 'C:\Users\Kris.garcia\code\open\sema\alcaeus-examples\getting-started-example\node_modules\parse-link-header'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
        - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "url": false }
  • Solution

* Same solution as for Problem 1 & 3

  1. Install the node-polyfill-webpack-plugin package
npm install --save-dev node-polyfill-webpack-plugin
  1. Configure the node-polyfill-webpack-plugin in the custom-webpack.config.ts file
import { Configuration } from 'webpack';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';

export default {
  plugins: [
    new NodePolyfillPlugin()
   ]
} as Configuration;

Problem 3 - resolving 'util'

  • Problem
./node_modules/rdf-dataset-ext/fromStream.js:5:4-19 - Error: Module not found: Error: Can't resolve 'util' in 'C:\Users\Kris.garcia\code\open\sema\alcaeus-examples\getting-started-example\node_modules\rdf-dataset-ext'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "util": false }
  • Solution

* Same solution as for Problem 1 & 2

  1. Install the node-polyfill-webpack-plugin package
npm install --save-dev node-polyfill-webpack-plugin
  1. Configure the node-polyfill-webpack-plugin in the custom-webpack.config.ts file
import { Configuration } from 'webpack';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';

export default {
  plugins: [
    new NodePolyfillPlugin()
   ]
} as Configuration;

Problem 4 - finding declaration file for 'clownface'

  • Problem
...
Error: ../../../../../Code/open/sema/alcaeus-examples/getting-started-example/node_modules/@tpluscode/rdfine/RdfResource.d.ts:4:56 - error TS7016: Could not find a declaration file for module 'clownface'. 'C:/Users/Kris.garcia/Code/open/sema/alcaeus-examples/getting-started-example/node_modules/clownface/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/clownface` if it exists or add a new declaration (.d.ts) file containing `declare module 'clownface';`

4 import { MultiPointer, GraphPointer, AnyPointer } from 'clownface';
                                                         ~~~~~~~~~~~


Error: ../../../../../Code/open/sema/alcaeus-examples/getting-started-example/node_modules/@tpluscode/rdfine/factory.d.ts:2:40 - error TS7016: Could not find a declaration file for module 'clownface'. 'C:/Users/Kris.garcia/Code/open/sema/alcaeus-examples/getting-started-example/node_modules/clownface/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/clownface` if it exists or add a new declaration (.d.ts) file containing `declare module 'clownface';`

2 import { AnyContext, AnyPointer } from 'clownface';
...
  • Solution
  1. Install the @types/clownface package
npm install --save-dev @types/clownface

Summary

While we understand that this is not in any way a bug with Alcaeus per se, we would like to see if there is anything that can be done to improve the getting started DX when working with typescript and webpack based tooling like that which Angular uses. We would like to understand whether this means adding details to the documentation or making changes to how Alcaeus itself is packaged or potentially to how certain dependencies of Alcaeus are packaged, etc.. Please let us know if we can provide anymore information or collaboration on this and thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions