Search code examples
javascriptnode.jsreactjssystemjs

Javascript systemJS Error Cannot find module


I have a little not project where I have installed systemJS.

Here is 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"
  }
}

In app.js I have done this:

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

var SystemJS = require('systemjs');

When I run the project it's giving me this error:

Error: Cannot find module "."

I'm following the instructions here:

https://github.com/systemjs/systemjs

This part:

var SystemJS = require('systemjs');

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

What I'm I doing wrong?


Solution

  • Your problems could be due to the fact that you have missed to configure systemjs - that is instruct it where to look for modules to load.

    For example the configuration can look something like this:

    System.config({
      baseURL: './lib',
    
      // Set paths your modules
      paths: {
        'angular': 'mode_modules/angular/angular.js',
        'angular-route': 'node_modules/angular-route/angular-route.js'
      }
    });
    

    If you would like to skip the tedious configuration part - you might want to look at JSMP - it takes care of configuration part automatically.