I need a functionality that can convert uploaded file (mostly .docx) content to HTML code. I thought of using the "mammoth" library.
I can't seem to configure my project so that it can use the "mammoth". Does anybody know what should I do to make it possible?
I have cleared all the compilation errors and when I build the project then it compiles fine. However, if I try to load the page I get this error:
Uncaught ReferenceError: process is not defined
at 50074 (util.js:109:1)
at __webpack_require__ (bootstrap:19:1)
at 6027 (html-writer.js:1:12)
at __webpack_require__ (bootstrap:19:1)
at 90765 (index.js:1:18)
at __webpack_require__ (bootstrap:19:1)
at 20133 (document-to-html.js:9:15)
at __webpack_require__ (bootstrap:19:1)
at 88933 (index.js:5:25)
at __webpack_require__ (bootstrap:19:1)
at 61735 (menu.component.html:5:26)
at __webpack_require__ (bootstrap:19:1)
at 34283 (document-list.component.html:3:47)
at __webpack_require__ (bootstrap:19:1)
at 32418 (exercises.component.html:3:46)
at __webpack_require__ (bootstrap:19:1)
Has anybody had experience using "mammoth" in Angular lately? How did you configure it?
I've found that maybe I should edit my "polyfills.ts" file but I can't find it since Angular CLI hides it and makes it uneditable for me. When I try to create my own polyfills.ts file I run into all kinds of import errors. If that's the case then can somebody provide me the content of polyfills.ts and how do I configure my project to use my file and not the Angular CLI one? All help is appreciated. I provided some file contents of the current state of the project.
My custom-webpack.config.js file:
const webpack = require("webpack");
module.exports = {
resolve: {
fallback: {
"path": require.resolve("path-browserify"),
"stream": require.resolve("stream-browserify")
}
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
}
My angular.json file:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"frontend": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./custom-webpack.config.js",
"replaceDuplicatePlugins": true
},
"outputPath": "dist/frontend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss",
"src/app/document-toolbar/ng-multiselect-dropdown.theme.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget": "AngularCustomWebpackConfig:build"
},
"configurations": {
"production": {
"browserTarget": "frontend:build:production"
},
"development": {
"browserTarget": "frontend:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "frontend:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"@angular/material/prebuilt-themes/pink-bluegrey.css",
"src/styles.scss"
],
"scripts": []
}
}
}
}
}
}
My package.json file:
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^15.2.0",
"@angular/cdk": "^15.2.2",
"@angular/common": "^15.2.2",
"@angular/compiler": "^15.2.0",
"@angular/core": "^15.2.2",
"@angular/forms": "^15.2.2",
"@angular/material": "^15.2.2",
"@angular/platform-browser": "^15.2.2",
"@angular/platform-browser-dynamic": "^15.2.0",
"@angular/router": "^15.2.0",
"@fortawesome/angular-fontawesome": "^0.12.1",
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/free-brands-svg-icons": "^6.2.1",
"@fortawesome/free-regular-svg-icons": "^6.2.1",
"@fortawesome/free-solid-svg-icons": "^6.2.1",
"@tinymce/tinymce-angular": "^7.0.0",
"bootstrap": "^5.2.3",
"jquery": "^3.6.4",
"mammoth": "^1.5.1",
"ng-multiselect-dropdown": "^0.3.9",
"ngx-bootstrap": "^10.2.0",
"path-browserify": "^1.0.1",
"popper.js": "^1.16.1",
"rxjs": "~7.8.0",
"stream-browserify": "^3.0.0",
"tslib": "^2.3.0",
"util": "^0.12.5",
"webpack": "^5.76.1",
"zone.js": "~0.12.0"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^15.0.0",
"@angular-devkit/build-angular": "^15.2.3",
"@angular/cli": "~15.2.2",
"@angular/compiler-cli": "^15.2.0",
"@types/jasmine": "~4.3.0",
"@types/jquery": "^3.5.16",
"@types/node": "^18.15.3",
"jasmine-core": "~4.5.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "^4.9.5",
"webpack-cli": "^5.0.1"
}
}
My tsconfig.app.json:
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": ["node"]
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
}