Javascript systemJS 错误找不到模块

标签 javascript node.js reactjs systemjs

我有一个没有安装 systemJS 的项目。

这是 package.json:

{
  "name": "mytest",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "systemjs": "^0.20.13"
  },
  "devDependencies": {
    "react-scripts": "1.0.7"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

在 app.js 中我这样做了:

import React, { Component } from 'react';
import './App.css';

var SystemJS = require('systemjs');

当我运行该项目时,它给了我这个错误:

错误:找不到模块“。”

我正在按照此处的说明进行操作:

https://github.com/systemjs/systemjs

这部分:

var SystemJS = require('systemjs');

// loads './app.js' from the current directory
SystemJS.import('./app.js').then(function (m) {
  console.log(m);
});

我做错了什么?

最佳答案

您的问题可能是由于您错过了 configure systemjs - 指示它在哪里寻找要加载的模块。

例如,配置可能如下所示:

System.config({
  baseURL: './lib',

  // Set paths your modules
  paths: {
    'angular': 'mode_modules/angular/angular.js',
    'angular-route': 'node_modules/angular-route/angular-route.js'
  }
});

如果您想跳过繁琐的配置部分 - 您可能需要查看 JSMP - 它自动处理配置部分。

关于Javascript systemJS 错误找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44541812/

相关文章:

javascript - 如果 URL 具有哈希值,则强制 Firefox 和 Edge 重新加载页面

javascript - 向 Safari 中 undefined object 原型(prototype)新添加的函数/属性

node.js - 如何解决此错误 "Error: recognize -- (FeatureNotLicensed) at: "OCRXpress Std""?

javascript - 删除 tslib 作为生产依赖项

node.js - 使用或不使用 'new' 关键字创建 Mongoose 模式?

javascript - 为什么我可以使用 this.state 而无需绑定(bind)或使用箭头函数 React

javascript - js解析json多个元素与单个元素

javascript - 将输入元素与表单中的某些按钮相关联?

reactjs - Recoil 中的动态原子键

javascript - React 检索(某些)DOM 值的方法