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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build can't find node_module ending in .js or starting with @ #310

Closed
rijkvanzanten opened this issue Aug 12, 2017 · 14 comments
Closed

Build can't find node_module ending in .js or starting with @ #310

rijkvanzanten opened this issue Aug 12, 2017 · 14 comments
Labels

Comments

@rijkvanzanten
Copy link

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
Trying to production build an app which uses a Node module which ends in .js (like headroom.js) results in a ENOENT error

If the current behavior is a bug, please provide the steps to reproduce.
Import a Node module ending in .js into your Preact app

What is the expected behavior?
It should require the module from node_modules/headroom.js

Please mention other relevant information.

  • node version: 8.2.1
  • npm version: 5.3.0
  • Operating system: MacOS Sierra 10.12.6
@thangngoc89
Copy link
Collaborator

How do you import your module? Could you generate a simply reproduce repo so I can clone and play with it?

@rijkvanzanten
Copy link
Author

Hi @thangngoc89

I import it the "regular" way:
import Headroom from 'headroom.js';

I just now noticed it also fails when I import an organization package like
import Player from '@vimeo/player';

I'll create a repo for you. I'll post a comment here with a link when it's done 🙂

@thangngoc89
Copy link
Collaborator

that's weird. I'll take a look. btw, I usually use https://github.com/KyleAMathews/react-headroom . it's super small with declarative API

@rijkvanzanten
Copy link
Author

Yeah I just changed to that one (it misses some of the options however) 🙂

I've uploaded a small demo on https://github.com/rijkvanzanten/preact-cli-import-demo

It is the default preact create app, with the import added to the home component https://github.com/rijkvanzanten/preact-cli-import-demo/blob/master/src/routes/home/index.js

@thangngoc89
Copy link
Collaborator

This looks like a bug in ours' implementation. Investigating it

@reznord
Copy link
Member

reznord commented Aug 12, 2017

@rijkvanzanten does it work fine when you pass a flag --no-prerender ?

@thangngoc89
Copy link
Collaborator

@reznord it doesn't work in dev mode too.

@rijkvanzanten
Copy link
Author

@reznord the no prerender flag doesn’t change anything

@rijkvanzanten rijkvanzanten changed the title Build can't find node_module ending in .js Build can't find node_module ending in .js or starting with @ Aug 14, 2017
@hassanbazzi
Copy link
Member

hassanbazzi commented Aug 15, 2017

no pre-render does fix it for me btw. Having this issue with import player from 'player.js'

Stack trace:

Template execution failed: Error: ENOENT: no such file or directory, open '/opt/app/src/~/player.js/dist/player-0.0.12.js'
  Error: ENOENT: no such file or directory, open '/opt/app/src/~/player.js/dist/  player-0.0.12.js'
  
  - prerender.js:69 handlePrerenderError
    [app]/[preact-cli]/lib/lib/webpack/prerender.js:69:33
  
  - prerender.js:52 prerender
    [app]/[preact-cli]/lib/lib/webpack/prerender.js:52:3
  
  - webpack-client-config.js:194 Object.ssr
    [app]/[preact-cli]/lib/lib/webpack/webpack-client-config.js:194:54
  
  - template.html:111 yS3i.module.exports
    /opt/app/src/template.html:111:37

@developit
Copy link
Member

I'm seeing it work without prerendering, so this makes me thinks it's related to our use of target:'node'.

@reznord
Copy link
Member

reznord commented Aug 16, 2017

It failed for me when I tried with preact build --no-prerender

@developit
Copy link
Member

ah it might just be dev vs prod. dev build (watch) worked for me

@jeffutter
Copy link

I just wanted to mention that this happens for me too. If you are trying to add --no-prerender when doing yarn run you have to run it as such: yarn run -- --no-prerender or it thinks the argument applies to yarn, not preact.

@reznord
Copy link
Member

reznord commented Aug 18, 2017

As @developit mentioned earlier, it is because of the SSR build that we are shipping by default.

We will be providing a better error stack trace when it fails on this in the future.

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

No branches or pull requests

6 participants