1

My npm run build fails with this:

✖ Building demo

Failed to compile with 1 error.

 ERROR  in multi ./node_modules/nwb/polyfills.js ./demo/src/index.js
Module not found: Error: Can't resolve '/Users/david/git/demoapp/demo/src/index.js' in '/Users/david/git/demoapp'
 @ multi ./node_modules/nwb/polyfills.js ./demo/src/index.js
Error running command: Build failed with errors.
Error: Build failed with errors.
at /Users/david/git/demoapp/node_modules/nwb/lib/webpackBuild.js:82:17
at emitRecords.err (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:269:13)
at Compiler.emitRecords (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:375:38)
at emitAssets.err (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:262:10)
at applyPluginsAsyncSeries1.err (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:368:12)
at next (/Users/david/git/demoapp/node_modules/tapable/lib/Tapable.js:218:11)
at Compiler.compiler.plugin (/Users/david/git/demoapp/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
at Compiler.applyPluginsAsyncSeries1 (/Users/david/git/demoapp/node_modules/tapable/lib/Tapable.js:222:13)
at Compiler.afterEmit (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:365:9)
at require.forEach.err (/Users/david/git/demoapp/node_modules/webpack/lib/Compiler.js:354:15)
at /Users/david/git/demoapp/node_modules/async/dist/async.js:473:16
at iteratorCallback (/Users/david/git/demoapp/node_modules/async/dist/async.js:1050:13)
at /Users/david/git/demoapp/node_modules/async/dist/async.js:958:16
at /Users/david/git/demoapp/node_modules/graceful-fs/graceful-fs.js:43:10
at FSReqWrap.oncomplete (fs.js:112:15)`

This is incorrect in '/Users/david/git/demoapp' because the index is in /Users/david/git/demoapp/src or /Users/david/git/demoapp/lib for the ES5 version, /Users/david/git/demoapp/es for the ES6 version

My nwb.config.js looks like this:

const path = require('path');

function excludeNodeModulesExcept (modules) {
var pathSep = path.sep;
if (pathSep === '\\') { // must be quoted for use in a regexp:
    pathSep = '\\\\';
}
var moduleRegExps = modules.map(function (modName) { return new RegExp("node_modules" + pathSep + modName);});

return function (modulePath) {
    if (/node_modules/.test(modulePath)) {
        for (var i = 0; i < moduleRegExps.length; i++) {
            if (moduleRegExps[i].test(modulePath)) {
                console.log("Allowed babel transpiling of " + modulePath);
                return false;
            }
        }
        return true;
    }
    return false;
};
}

module.exports = {
type: 'react-component',
npm: {
    esModules: true,
    umd: false
},
webpack: {
    rules: {
        babel: {
            exclude: excludeNodeModulesExcept(['kontraktor-client', 'kontraktor-common']),
            options: {
                babelrc: false,
                cacheDirectory: true
            }
        }
    }
}
};

The relevant part of my package.json looks like this:

{
"name": "demoapp",
"version": "1.0.0",
"description": "Demo App",
"main": "lib/index.js",
"module": "es/index.js",
"files": [
"css",
"es",
"lib",
"umd"
],
"scripts": {
"build": "nwb build-react-component",
"images": "node imagesServer/index.js",
"serve": "nwb serve-react-app",
"clean": "nwb clean-module",
"start": "npm-run-all --parallel serve images",
"test": "nwb test-react",
"test:coverage": "nwb test-react --coverage",
"test:watch": "nwb test-react --server"
},

Is there a way of specify to nwb where the source index.js is located? I want to build a ES5 version of this React application.

Another confusion is that some posts and tutorials states that a directory named 'dist' is used to output the built code from 'npm run build'?

oldDave
  • 395
  • 6
  • 25

1 Answers1

0

react-app doesnot support importing files outside src folder. so short answer ;you will have to eject'

or you can use npm link but your module must be exporting es5 beacuse again react-app will not transpile it for you.

Zalaboza
  • 8,899
  • 16
  • 77
  • 142