Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

import syntax support in server-side src/node_modules #467

Open
Fi1osof opened this issue Aug 6, 2018 · 4 comments
Open

import syntax support in server-side src/node_modules #467

Fi1osof opened this issue Aug 6, 2018 · 4 comments

Comments

@Fi1osof
Copy link

Fi1osof commented Aug 6, 2018

Type of issue

Bug

Current behavior

Places in src/node_modules/ components did not parse.

(function (exports, require, module, __filename, __dirname) { import React from 'react'

Expected behavior

Places in src/node_modules/ components will parse as well.

By react-scripts parsed well. Officialy. facebook/create-react-app#1065

Your environment

  • fusion-cli version: 1.8.4

  • Node.js version (node --version): 9.11.1

  • npm version (npm --version): 6.3.0

  • Operating System: Ubuntu-18

@KevinGrandon
Copy link
Contributor

Thanks for filing a bug report. We should be transpiling node_modules, so it's strange that you're seeing this. Here is our test case around node_module transpilation:

test('transpiles node_modules', async t => {
const envs = ['development'];
const dir = './test/fixtures/transpile-node-modules';
const clientVendorPath = path.resolve(
dir,
`.fusion/dist/${envs[0]}/client/client-vendor.js`
);
const compiler = new Compiler({envs, dir});
await compiler.clean();
const watcher = await new Promise((resolve, reject) => {
const watcher = compiler.start((err, stats) => {
if (err || stats.hasErrors()) {
return reject(err || new Error('Compiler stats included errors.'));
}
return resolve(watcher);
});
});
watcher.close();
t.ok(await exists(clientVendorPath), 'Client vendor file gets compiled');
const clientVendor = await readFile(clientVendorPath, 'utf8');
t.ok(
clientVendor.includes(`$return('fixturepkg_string')`),
'async/await is transpiled in fixture node_module'
);
t.end();
});

We might need to add some assertions, or get an example repo that demonstrates this issue in order to debug this.

@Fi1osof
Copy link
Author

Fi1osof commented Aug 6, 2018

@KevinGrandon thanks for answer.
Not node_modules, but src/node_modules/
In react-scripts, if i wont include my custom packages globaly, i can put them into src/node_modules and import them by name.
For example file src/node_modules/MyApp/index.js
in src/main.js i can do just import MyApp from 'MyApp'; Not import MyApp from './node_modules/MyApp';

Now, when i do this, fusion-cli fined them (not say "can not find module MyApp"), but can not parse them with error "Unexpected token import". Just ignored **/node_modules.

@rtsao
Copy link
Member

rtsao commented Aug 6, 2018

Fusion.js currently transpiles and bundle node_modules for the browser bundle, but unlike create-react-app, Fusion.js also has a server app. Because of the possibility of binary Node.js modules in node_modules, we do not include these in the server bundle.

That said, I think it might be reasonable to assume src/node_modules, by virtue of being inside src/, would not have any binary dependencies and thus could be transpiled/bundled into the server bundle.

To do this, I think we would simply need to adjust the appropriate globs accordingly.

@Fi1osof
Copy link
Author

Fi1osof commented Aug 6, 2018

@rtsao i have my own projects with react-scripts SSR (not so cool like fusion :) ), and src/node_modules/ correct resolves on server-side too.

@rtsao rtsao changed the title Unexpected token import in src/node_modules import syntax support in server-side src/node_modules Aug 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants