首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块未找到:错误:无法解析'fs‘角

模块未找到:错误:无法解析'fs‘角
EN

Stack Overflow用户
提问于 2018-06-29 04:52:35
回答 1查看 6.9K关注 0票数 5

我在角应用程序中实现Mapbox,如下所示

将css添加到角-cli.json中

"../node_modules/@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css"

组件

代码语言:javascript
复制
import { Component } from '@angular/core';
import * as mapboxgl from 'mapbox-gl';
import * as MapboxDraw from '@mapbox/mapbox-gl-draw';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  static t;
  ngOnInit() {
    mapboxgl.accessToken = 'Token';
    AppComponent.t.map= new mapboxgl.Map({
      container: 'map',
      style: 'mapbox://styles/mapbox/light-v9',
      zoom: 5,
      center: [-78.880453, 42.897852]
    });

     const draw = new MapboxDraw({
        displayControlsDefault: false,
        controls: {
            polygon: true,
            trash: true
        }
    });
    AppComponent.t.map.addControl(draw);
  }
}

它的显示无法编译

./node_modules/jsonlint-lines/lib/jsonlint.js Module not found: Error: Can't resolve 'fs' in 'C:\angular\mapboxdemo\node_modules\jsonlint-lines\lib'

下面是我的package.json

代码语言:javascript
复制
{
  "name": "mapboxdemo",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/cli": "^1.7.4",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@mapbox/mapbox-gl-draw": "^1.0.9",
    "core-js": "^2.5.4",
    "mapbox-gl": "^0.46.0",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  },
  "browser": {
    "fs": false,
    "path": false,
    "os": false
  }
}

我尝试执行ng eject命令以生成webpack.config文件,并尝试添加{ fs:“空”},但在错误下面抛出

我怎么才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2021-01-26 12:32:12

打开package.json文件,将其添加到浏览器对象中。

代码语言:javascript
复制
  "browser": {
     "fs": false,
     "path": false,
     "os": false}

如果您的模块要用于客户端,则应该使用浏览器字段而不是主字段。这有助于提醒用户,它可能依赖于Node.js模块中不可用的原语。

来源:npm文档\ package.json

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51094521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档