1
votes

I'm trying to run npm test in my tfs build, but I get everytime I get an ENOENT error:

C:\Program Files\nodejs\npm.cmd run test

npm ERR! path E:\Agents\agent_work\38\package.json

npm ERR! code ENOENT

npm ERR! errno -4058

npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'E:\Agents\agent_work\38\package.json'

npm ERR! enoent This is related to npm not being able to find a file.

I followed this tutorial of Microsoft to set up my build and I also included npm cache clean, because I read that if you get enoent during install that might fix it.

When I run npm test locally it works fine

Below are my config files.

This is karma.config.js:

module.exports = function (config) {
    var testWebpackConfig = require('./webpack.test.js');
  config.set({

    basePath: '.',
    frameworks: ['jasmine'],

    plugins: [
        require('karma-jasmine'),
        require('karma-phantomjs-launcher'),
        require('karma-webpack'),
        require('karma-sourcemap-loader'),
        require('karma-jasmine-html-reporter'),
        require('karma-junit-reporter')
    ],

    // list of files / patterns to load in the browser
    files: [
        { pattern: 'spec.bundle.js', watched: false }
    ],

    preprocessors: {
        'spec.bundle.js': ['webpack', 'sourcemap']
    },

    // webpack
    webpack: testWebpackConfig,

    reporters: ['progress', 'kjhtml', 'junit'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false,
    concurrency: Infinity,
    junitReport: {
        outputDir: '',
        outputFile: 'test.xml'
    }
  })
}

This is spec.bundle.js:

import 'core-js';
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';

import { getTestBed } from '@angular/core/testing';
import {
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

import 'rxjs';

getTestBed().initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
);

var testContext = require.context('./src', true, /\.spec\.ts/);

function requireAll(requireContext) {
    return requireContext.keys().map(requireContext);
}

var modules = requireAll(testContext);
1

1 Answers

1
votes

The error message indicated that npm test command cannot find the "package.json" file. Please make sure that your package.json file is uploaded into source control and downloaded during the build process and you configured the correct path to the package.json file (Working folder with package.json) for npm task in your build definition.