Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

WinJS is not copied when adding windows platform #341

Closed
3 tasks done
feiandytan opened this issue Jun 25, 2019 · 14 comments
Closed
3 tasks done

WinJS is not copied when adding windows platform #341

feiandytan opened this issue Jun 25, 2019 · 14 comments
Milestone

Comments

@feiandytan
Copy link

Bug Report

Problem

WinJS is not copied when adding windows platform to cordova application.

What is expected to happen?

The winjs\js\base.js should be copied correctly.

What does actually happen?

The winjs\js\base.js is not copied, and the console prints the error log:
cp: no such file or directory: C:\Users\i062893\cordova-workspace\attachmenttest\node_modules\cordova-windows\node_modules\winjs\js\base.js

Information

Command or Code

I use following commands:

C:\Users\i062893\cordova-workspace>cordova --version
9.0.0 ([email protected])

C:\Users\i062893\cordova-workspace>cordova create attachmenttest
Creating a new cordova project.

C:\Users\i062893\cordova-workspace>cd attachmenttest

C:\Users\i062893\cordova-workspace\attachmenttest>cordova platforms add windows
Using cordova-fetch for cordova-windows@^7.0.0
Adding windows project...
Creating Cordova Windows Project:
Path: platforms\windows
Namespace: io.cordova.hellocordova
Name: HelloCordova
cp: no such file or directory: C:\Users\i062893\cordova-workspace\attachmenttest\node_modules\cordova-windows\node_modules\winjs\js\base.js

cp: no such file or directory: C:\Users\i062893\cordova-workspace\attachmenttest\node_modules\cordova-windows\node_modules\winjs\js\base.js

Windows project created with [email protected]
Plugin 'cordova-plugin-whitelist' found in config.xml... Migrating it to package.json
Discovered saved plugin "cordova-plugin-whitelist". Adding it to the project
Installing "cordova-plugin-whitelist" for windows
Adding cordova-plugin-whitelist to package.json

Environment, Platform, Device

Version information

Cordova: 9.0.0
cordova-windows: 7.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@janpio
Copy link
Member

janpio commented Jun 26, 2019

This has already been fixed with #331, but not released yet: 7.0.0...master

@regnete
Copy link

regnete commented Jul 4, 2019

Temporarily fix via cordova hook when using unfixed version 7.0.0:

config.xml:

<platform name="windows">
        <hook type="before_prepare" src="hooks/win_winjs_fix.js" />
</platform>

hooks/win_winjs_fix.js:

const path = require('path');
const shell = require('shelljs');
const fs = require('fs');

module.exports = function (ctx)
{

    if (!ctx.opts.platforms.includes('windows'))
        return;


    return new Promise(function (resolve, reject)
    {
        const root = ctx.opts.projectRoot;
        const projectPath = path.join(root, 'platforms', 'windows');
        const destinationDirectory = path.join(projectPath, 'platform_www', 'WinJS', 'js');
        const destBaseJsPath = path.join(destinationDirectory, 'base.js');
        //var srcBaseJsPath = path.join(root, 'node_modules', 'winjs', 'js', 'base.js');
        const srcBaseJsPath = require.resolve('winjs/js/base');
        fs.mkdirSync(destinationDirectory, { recursive: true });
        shell.cp('-f', srcBaseJsPath, destBaseJsPath);
        resolve();
    });

};

@Jahrenski
Copy link

Temporarily fix via cordova hook when using unfixed version 7.0.0:

config.xml:

<platform name="windows">
        <hook type="before_prepare" src="hooks/win_winjs_fix.js" />
</platform>

hooks/win_winjs_fix.js:

const path = require('path');
const shell = require('shelljs');
const fs = require('fs');

module.exports = function (ctx)
{

    if (!ctx.opts.platforms.includes('windows'))
        return;


    return new Promise(function (resolve, reject)
    {
        const root = ctx.opts.projectRoot;
        const projectPath = path.join(root, 'platforms', 'windows');
        const destinationDirectory = path.join(projectPath, 'platform_www', 'WinJS', 'js');
        const destBaseJsPath = path.join(destinationDirectory, 'base.js');
        //var srcBaseJsPath = path.join(root, 'node_modules', 'winjs', 'js', 'base.js');
        const srcBaseJsPath = require.resolve('winjs/js/base');
        fs.mkdirSync(destinationDirectory, { recursive: true });
        shell.cp('-f', srcBaseJsPath, destBaseJsPath);
        resolve();
    });

};

I suggest you put the mkdir in a try catch otherwise it will be blocking the compile most of the time.
try { fs.mkdirSync(destinationDirectory, { recursive: true }); } catch (err) { if (err.code !== 'EEXIST') throw err; }

@janpio janpio added this to the 7.1.0 milestone Jul 15, 2019
@pjc2007
Copy link

pjc2007 commented Aug 14, 2019

I tried adding the above hook in config.xml, and the win_winjs_fix.js from @Jahrenski, I removed and readded windows to my Ionic/Cordova project, but I still get the error when adding Windows. I don't have the node_modules\cordova-windows\node_modules\winjs folder.

@darylldawn
Copy link

@pjc2007 any updates with this? Currently facing the same problem while waiting for the official release.

@pjc2007
Copy link

pjc2007 commented Aug 22, 2019

@darylldawn - no unfortunately. At the moment I cannot build the Windows version of my app at all. e.g. I get this error.. Not sure if it related to this one. Soon, the need to going to become more urgent for me.

@feiandytan
Copy link
Author

@pjc2007 , [email protected] is working. You can downgrade the cordova-windows by running the commands:

cordova platform rm windows
cordova platform add [email protected]

@pjc2007
Copy link

pjc2007 commented Aug 22, 2019

@feiandytan - thankyou! I tried what you suggested and I not longer get the error. I do still get my build errors with my Ionic Windows SQLite project ie

fatal error C1083: Cannot open include file: 'winapifamily.h': No such file or directory [D:\dev\myapp\plugins\cordova-sqlite-storage\src\windows\SQLite3-WinRT-sync\SQLite3\SQLite3.UWP.vcxproj]

but I now know that is not related to this issue

@darylldawn
Copy link

darylldawn commented Aug 22, 2019

@pjc2007 Hey, I was able to build just a while ago with @regnete's solution. I didn't have the same exact error as you, but I was initially having problems with SQLite3. After installing all the dependencies
(Platform Toolset, Windows 10 SDK, etc) via Visual Studio Installer, setting an environment variable (sqlite related) and finally hooking the temporary fix above, I was able to run.

Since it might be related to one of the plugins you are currently using (I have a hunch it might be the sqlite plugin -- I also did the remove and add one by one plugin procedure), you can also check out issues at their respective repositories (but of course I think you might already have).

Looking forward to the 7.1.0 release!

@pjc2007
Copy link

pjc2007 commented Aug 22, 2019

@darylldawn - ok thanks, Yes I will need to do all that. I think my Visual Studio and related tools may be messed up after a few uninstalls and updates of them. Perhaps Visual Studio 2019 install mucked it up.

@brodycj
Copy link

brodycj commented Dec 3, 2019

@janpio I think we still need to make this release. I recall it was discussed on the mailing list but was stalled for some reason (we were waiting for a response on something). Any way we can unblock the release?

@janpio
Copy link
Member

janpio commented Dec 3, 2019

Feel free to take over and figure things out. I can and will not spend time on this right now or the near future.

@brodycj
Copy link

brodycj commented Dec 3, 2019

Thanks @janpio, I will take it over when I get a chance.

@brodycj
Copy link

brodycj commented Jan 6, 2020

This should be fixed in [email protected] patch release. Please report if this issue continues to persist in 7.0.1 or any later releases.

@brodycj brodycj closed this as completed Jan 6, 2020
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

7 participants