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

Import from index files doesn't work #235

Closed
cjorasch opened this issue Oct 10, 2017 · 4 comments
Closed

Import from index files doesn't work #235

cjorasch opened this issue Oct 10, 2017 · 4 comments
Assignees

Comments

@cjorasch
Copy link

Stencil version:

@stencil/core@0.0.6-13

I'm submitting a ...
[x] bug report

Current behavior:
Unable to resolve references to index.js files.

Expected behavior:
It should be possible to import from index files.

Steps to reproduce:

If the project has a directory of shared utilities in /src/util/.

  1. Create an index.ts file in src/util.
  2. Import { MyUtil } from '../util';
  3. nom start

This results in the following error:

[25:34.3]  bundle modules started ...
[25:34.3]  bundle modules finished in 14 ms

[ ERROR ]  Could not resolve '../util' from dist/collection/core/components/my-component.js

If you use Import { MyUtil } from '../util/index'; then you do not get the error.

A similar error occurs if any downstream references use index files. For example, if my-util.ts includes a reference to another class via a directory index.

TypeScript compilation works fine. It is the Stencil process that gets the error.

@jthoms1
Copy link
Contributor

jthoms1 commented Oct 19, 2017

Could you provide me with your tsconfig.json file contents? I want to make sure that you have allowJs set to true. Looks like our starter does not have this set and by default it is false.

@cjorasch
Copy link
Author

I am using the config that is in stencil-app-starter.

I updated it to include allowJs and still get an error.

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "allowJs": true,
    "declaration": false,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "moduleResolution": "node",
    "module": "es2015",
    "target": "es2015",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "jsx": "react",
    "jsxFactory": "h"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

My code includes an import from ../shared (the directory that contains the index). When I use nom start I get the following:

[54:16.1]  @stencil/core v0.0.6-21
[54:16.2]  build, dev mode, started ...
[54:16.2]  compile started ...
[54:17.9]  compile finished in 1.78 s
[54:17.9]  bundle styles started ...
[54:17.9]  bundle modules started ...
[54:18.1]  bundle styles finished in 151 ms
[54:18.4]  bundle modules finished in 437 ms

[ ERROR ]  Could not resolve '../shared' from dist/collection/components/my-component.js

[54:18.4]  build failed, watching for changes... in 2.25 s


[ ERROR ]  Could not resolve '../shared' from dist/collection/components/my-component.js

If I change my code to import from ../shared/index then I do not get the error.

@jthoms1 jthoms1 added bug and removed feature labels Oct 19, 2017
@jthoms1
Copy link
Contributor

jthoms1 commented Oct 19, 2017

Ya this looks like a bug to me. I think it might be a setup issue with Rollup. I will research further.

@jthoms1
Copy link
Contributor

jthoms1 commented Oct 31, 2017

Rollup does not resolve index files from paths. It appears that we need to add a rollup plugin to allow for this. https://github.com/frostney/rollup-plugin-local-resolve

Or use the app-scripts code.
https://github.com/ionic-team/ionic-app-scripts/blob/v2.1.4/src/rollup/ionic-rollup-resolver-plugin.ts#L93-L122

@jthoms1 jthoms1 closed this as completed in 25591e4 Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants