Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundled app can't resolve path to core.*.node #2768

Closed
quarties opened this issue Mar 11, 2019 · 2 comments
Closed

Bundled app can't resolve path to core.*.node #2768

quarties opened this issue Mar 11, 2019 · 2 comments

Comments

@quarties
Copy link

quarties commented Mar 11, 2019

馃悰 bug report

After upgrading parcel-bundler from 1.11.0 to 1.12.0 our app throws an error when we try to run it after building.

馃帥 Configuration (.babelrc, package.json, cli command)

Here is a command that I used:

node index.js config.json

馃 Expected Behavior

It should run the app.

馃槸 Current Behavior

The app is not starting and throws an error:

/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:116
    throw error;
    ^

Error: Cannot find module './../../../../backend/core.c3506fea.node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at newRequire (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:34:18)
    at localRequire (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:53:14)
    at eval (eval at parcelRequire.dz+m (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:31333:16), <anonymous>:1:1)
    at Object.parcelRequire.dz+m (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:31333:16)
    at newRequire (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:47:24)
    at localRequire (/Users/michalsypko/Sites/bigcommerce/dist/backend/index.js:53:14)

馃敠 Context

We are using lerna for our project to build backend and frontend of the app. It worked just fine with parcel-bundler@1.11.0.

馃實 Your Environment

Software Version(s)
Parcel 1.12.0
Node 10.11.0
npm 6.4.1
Operating System MacOS Mojave v10.14.3
@quarties
Copy link
Author

quarties commented Mar 11, 2019

Additionally, here is the source code of @livechat/parcel-plugin-node-addons (loaded in devDependencies):

index.js

module.exports = function(bundler) {
    bundler.addAssetType('node', require.resolve('./NodeAsset'));
}

NodeAsset.js

const { Asset } = require('parcel-bundler');
const path = require('path');
const URL = require('url');

class NodeAsset extends Asset {
    
    load() {}

    generate() {
        const pathToAsset = this.urlJoin(
            this.options.publicURL,
            this.generateBundleName()
        );
    
        return [
            {
                type: 'js',
                value: `module.exports=eval('require(${JSON.stringify(`.${pathToAsset}`)})');`
            }
        ];
    }

    urlJoin(publicURL, assetPath) {
        const url = URL.parse(publicURL, false, true);
        const assetUrl = URL.parse(assetPath);
        url.pathname = path.posix.join(url.pathname, assetUrl.pathname);
        url.search = assetUrl.search;
        url.hash = assetUrl.hash;

        return URL.format(url);
    }
}

module.exports = NodeAsset;

@mischnic
Copy link
Member

Fixed by #2740

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants