cli: Cannot import json file with text plugin or json plugin

I’m submitting a bug report

  • Library Version: 0.18.0

Please tell us about your environment:

  • Operating System: Windows 7

  • Node Version: 5.10.1

  • NPM Version: 3.8.6

  • Browser: Chrome 52.0

  • Language: ESNext

Current behavior: We have several json files that we import into the client. With SystemJS we were doing import _defaults from './entity-default-definitions.json!json';

I’ve tried switching to import _defaults from 'json!./entity-default-definitions.json'; which produces { uid: 8, name: ‘writeBundles’, branch: false, error: { [Error: ENOENT: no such file or directory, open 'D:\Users\kminio\src2\tw-composer\thingworx-ui-platform\src\json.js '] errno: -4058, code: ‘ENOENT’, syscall: ‘open’, path: ‘D:\Users\kminio\src2\tw-composer\thingworx-ui-platform\src\json.js’, moduleTree: [ ‘entity/entity-defaults’ ], fileName: ‘D:/Users/kminio/src2/tw-composer/thingworx-ui-platform/src/entity/entity-defaults.js’ }, duration: [ 5, 603011213 ], time: 1472497970464 }

and also import _defaults from 'text!./entity-default-definitions.json'; closer but produces: { uid: 8, name: ‘writeBundles’, branch: false, error: [TypeError: Path must be a string. Received undefined], duration: [ 5, 706117176 ], time: 1472498084764 }

Expected/desired behavior:

  • What is the expected behavior? If I could load directly using requirejs json plugin that would be ideal. I could load as text and do a JSON.parse to achieve as well.
  • What is the motivation / use case for changing the behavior? Migrating to CLI from JSPM/SystemJS

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

I could import a json file by creating a textProcessor step.

aurelia.json

"textProcessor": {
    "displayName": "Text",
    "source": "src/**/*.json"
  },

process-text.js

import gulp from 'gulp';
import changedInPlace from 'gulp-changed-in-place';
import project from '../aurelia.json';
import {build} from 'aurelia-cli';

export default function processText() {
  return gulp.src(project.textProcessor.source)
    .pipe(changedInPlace({firstPass: true}))
    .pipe(build.bundle());
}

And finally

import Routes from 'text!../routes.json';
JSON.parse(Routes.app);

You can also add watchers to rebuild the app when changing json files.