Strip-Ansi using require() instead of import, generating exception

Discussão em 'Angular' iniciado por Paul Holmes, Janeiro 7, 2025.

  1. Paul Holmes

    Paul Holmes Guest

    I have an angular 13 project and when I try to serve the project I get this error:


    An unhandled exception occurred: require() of ES Module C:\Users\username\Documents\project\builds\Production2\tbsis\UI\node_modules\ansi-regex\index.js from C:\Users\username\Documents\project\builds\Production2\tbsis\UI\node_modules\strip-ansi\index.js not supported.
    ​

    This is the content of C:\Users\username\Documents\project\builds\Production2\tbsis\UI\node_modules\strip-ansi\index.js:

    'use strict';
    const ansiRegex = require('ansi-regex');

    module.exports = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;


    It seems this require statement is causing the error.

    How can I get around this?

    I tried changing it to

    import ansiRegex from 'ansi-regex';


    But that gave this error when trying to serve


    An unhandled exception occurred: Cannot use import statement outside a module See "C:\Users\username\AppData\Local\Temp\ng-Z69dHd\angular-errors.log" for further details.
    ​

    Here is my package.json

    {
    "name": "client",
    "version": "0.0.0",
    "type": "module",
    "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "startl": "ng serve --base-href \"\\\"",
    "build": "ng build ",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
    },
    "postinstall": "ngcc",
    "private": true,
    "dependencies": {
    "@angular-devkit/schematics": "^13.1.4",
    "@angular/animations": "^13.1.2",
    "@angular/cli": "^13.1.2",
    "@angular/common": "^13.1.2",
    "@angular/compiler": "^13.1.2",
    "@angular/core": "^13.1.2",
    "@angular/forms": "^13.1.2",
    "@angular/platform-browser": "^13.1.2",
    "@angular/platform-browser-dynamic": "^13.1.2",
    "@angular/router": "^13.1.2",
    "@fortawesome/fontawesome-free": "^5.3.1",
    "ag-grid-angular": "^22.1.1",
    "ag-grid-community": "^22.1.1",
    "bootstrap": "^5.1.3",
    "core-js": "^2.5.4",
    "jquery": "^3.3.1",
    "ngx-bootstrap": "8.0.0",
    "node-gyp": "^7.1.2",
    "npm": "^8.3.1",
    "rxjs": "7.4.0",
    "tslib": "^2.3.1",
    "zone.js": "0.11.4"
    },
    "devDependencies": {
    "@angular-devkit/build-angular": "^13.1.3",
    "@angular/compiler-cli": "^13.1.2",
    "@angular/language-service": "^13.1.2",
    "@types/jasmine": "3.9.1",
    "@types/jasminewd2": "2.0.10",
    "@types/node": "12.12.6",
    "codelyzer": "^6.0.1",
    "grunt": "^1.4.1",
    "grunt-cli": "^1.4.3",
    "grunt-war": "^0.5.1",
    "jasmine-core": "^3.9.0",
    "jasmine-spec-reporter": "^7.0.0",
    "karma": "^6.3.4",
    "karma-chrome-launcher": "^3.1.0",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "^4.0.1",
    "karma-jasmine-html-reporter": "^1.7.0",
    "protractor": "^7.0.0",
    "ts-node": "^5.0.1",
    "tslint": "^6.1.0",
    "typescript": "^4.4.4"
    },
    "overrides": {
    "postcss": "8.2.13",
    "ansi-regex": "6.0.1",
    "node-forge": "1.3.1",
    "qs" : "6.10.3",
    "@angular/core" : "^13.1.2"
    }

    }

    Continue reading...

Compartilhe esta Página