wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
759 stars 45 forks source link

import native external ES2015 module via webpack #616

Closed kwonoj closed 8 years ago

kwonoj commented 8 years ago

Issue description or question

One of codebases import native ES2015 code directly, let webpack transpiles it by explicitly via babel-loader. Trying to achieve same behavior in wallaby, not using babel-loader (since wallaby uses own compiler instead of webpack loader) but wasn't succeed so far, seeing below error messages currently.

local-db.js

import * as _ from 'underscore';
import localforage from 'localforage/src/localforage';

localforage.createInstance(...);

Error

SyntaxError: Parse error ​at http://localhost:53811/__modules/71.js?1464428536835:1 ​ModuleNotFoundError: Module not found: Error: a dependency to an entry point is not allowed ​ at c:\sw\apps\app\node_modules\webpack\lib\Compilation.js:254:7 ​ at c:\sw\apps\app\node_modules\webpack\lib\NormalModuleFactory.js:58:13 ​ at NormalModuleFactory. (c:\sw\apps\app\node_modules\tapable\lib\Tapable.js:82:11) ​ at NormalModuleFactory. (c:\sw\apps\app\node_modules\webpack\lib\NormalModuleReplacementPlugin.js:37:11) ​ at NormalModuleFactory.applyPluginsAsyncWaterfall (c:\sw\apps\app\node_modules\tapable\lib\Tapable.js:86:13) ​ at onDoneResolving (c:\sw\apps\app\node_modules\webpack\lib\NormalModuleFactory.js:38:11) ​ at onDoneResolving (c:\sw\apps\app\node_modules\webpack\lib\NormalModuleFactory.js:121:6) ​ at c:\sw\apps\app\node_modules\webpack\lib\NormalModuleFactory.js:116:7 ​ at c:\sw\apps\app\node_modules\webpack\node_modules\async\lib\async.js:726:13 ​ at c:\sw\apps\app\node_modules\webpack\node_modules\async\lib\async.js:52:16

71.js in wallaby cache : bundles raw localforage.js

window.__moduleBundler.cache[71] = [function(__webpack_require__, module, exports) {import isIndexedDBValid from './utils/isIndexedDBValid';
import isWebSQLValid from './utils/isWebSQLValid';
import isLocalStorageValid from './utils/isLocalStorageValid';
import idbDriver from './drivers/indexeddb';
import websqlDriver from './drivers/websql';
import localstorageDriver from './drivers/localstorage';
import serializer from './utils/serializer';
import Promise from './utils/promise';
import executeTwoCallbacks from './utils/executeTwoCallbacks';

// Custom drivers are stored here when `defineDriver()` is called.
// They are shared across all instances of localForage.
var CustomDrivers = {};
...
  1. Can I get some help to resolve issue in subj.?
  2. Does ​ModuleNotFoundError: Module not found: Error: a dependency to an entry point is not allowed also related to this issue also? I can't see additional context to analyze, and enabling debug:true makes editor freeze.

    Wallaby.js configuration file

var wallabyWebpack = require('wallaby-webpack');
var path = require('path');
var glob = require('glob');
var webpack = require('webpack');
var babel = require('babel-core');

module.exports = function (wallaby) {
    return {
        files: [{
            pattern: 'main/**/!(*-test).js',
            load: false
        }, {
            pattern: 'mocks/**/*.js',
            load: false,
            instrument: false
        }, {
            pattern: 'node_modules/localforage/**/*.js',
            load: false
        }, {
            pattern: 'main/**/*.html',
            load: true,
            instrument: false
        }, {
            pattern: 'main/**/*.ejs',
            load: true,
            instrument: false
        }, {
            pattern: 'assets/**/*',
            load: true,
            instrument: false
        }],

        tests: [{
            pattern: 'main/**/*-test.js',
            load: false
        }],

        compilers: {
            '**/*.js': wallaby.compilers.babel({
                babel: babel,
                presets: ['es2015']
            })
        },

        postprocessor: wallabyWebpack({
            entryPatterns: [
                'main/app-run.js',
                'mocks/**/*.js',
                '**/*-test.js'
            ],

            resolve: {
                //root: path.resolve(__dirname),
                root: path.resolve(wallaby.projectCacheDir),
                extensions: ['', '.js', '.json']
            },

            module: {
                loaders: [
                    {
                        test: /\.ejs$/,
                        loader: 'underscore-template-loader',
                        query: {
                            engine: 'underscore',
                        }
                    },

                    {
                        test: /\.html$/,
                        loaders: [
                            'html?' + JSON.stringify({
                                attrs: ['img:src', 'img:ng-src']
                            })
                        ]
                    }
                ],

                noParse: [
                    /^jquery(\-.*)?$/,
                    /^angular(\-.*)?$/
                ]
            },

            plugins: [
                new webpack.DefinePlugin({
                    __PRODUCTION__: true
                }),

                new webpack.NormalModuleReplacementPlugin(/\.(jpe?g|png|gif|svg|ico|css|txt|ttf|eot|woff(2))/, 'node-noop')
            ]
        }),

        bootstrap: function () {
            // required to trigger test loading
            window.__moduleBundler.loadTests();
        },
        workers: {
            initial: 1,
            regular: 1
        }
    };
};

Code editor or IDE name and version

Visual Studio Code v0.10.x / Wallaby Core v1.0.237

OS name and version

Windows 10

ArtemGovorov commented 8 years ago

Could you please share a small sample repo where I could reproduce the issue? Without seeing the repo, my only suggestion is to try this:

{
            pattern: 'node_modules/localforage/**/*.js',
            load: false
}

pattern from your files list,

kwonoj commented 8 years ago

Since it's config for non-oss work, I may need effort to try to create seperate codebase to replicate this. I'll try your advice first, then will spend some time to create one if it doesn't work.

Thanks for tips, closing for now and will reopen once I have sample project in place.

ArtemGovorov commented 8 years ago

No worries, I think the babel-loader for the node module should work for you (and it's easy to try). Let me know if it doesn't.