-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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:
-
Download, unzip, and open our example Angular App: alcaeus-app.zip (based on the default Angular CLI template)
-
Install Alcaeus
npm install --save alcaeus
- 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());
}
}- Try to run the application
npm start
- 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
- Install the
node-polyfill-webpack-pluginpackage
npm install --save-dev node-polyfill-webpack-plugin
- Configure the
node-polyfill-webpack-pluginin 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
- Install the
node-polyfill-webpack-pluginpackage
npm install --save-dev node-polyfill-webpack-plugin
- Configure the
node-polyfill-webpack-pluginin 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
- Install the
node-polyfill-webpack-pluginpackage
npm install --save-dev node-polyfill-webpack-plugin
- Configure the
node-polyfill-webpack-pluginin 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
- Install the
@types/clownfacepackage
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!